- version_compare: documentation ( source)
- str_replace: documentation ( source)
- preg_replace: documentation ( source)
- json_encode: documentation ( source)
<?php
//if (version_compare(PHP_VERSION, '5.2', '<')) {
// exit 'no json_encode() support';
//}
$array = array('text' => "£ Â <h1>Кириллический URL</h1>\n<p>This is Cyrillic URL example. Try <a class=js-as dir=rtl href=עברית>RTL עברית</a>.</p>\n");
if (version_compare(PHP_VERSION, '5.4', '>=')) {
$data = json_encode($array, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} else {
//$data = json_encode($array);
$data = preg_replace('/\\\\u([a-f0-9]{4})/e', "iconv('UCS-4LE', 'UTF-8', pack('V', hexdec('U$1')))", json_encode($array));
$data = str_replace('\\/', '/', $data);
}
echo $data;