note 73697 modified in function.preg-replace by nlopess
| From: | nlopess@php.net | Date: | Sun, 11 Mar 2007 12:44:11 +0000 |
| Subject: | note 73697 modified in function.preg-replace by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124324@lists.php.net to get a copy of this message | ||
I could not find a function to unescape javascript unicode escapes anywhere (e.g.,
"\u003c"=>"<").
<?php
function js_uni_decode($s) {
return preg_replace('/\\\u([0-9a-f]{4})/ie', "chr(hexdec('\\1'))",
$s);
}
echo js_uni_decode("\u003c");
?>
--was--
I could not find a function to unescape javascript unicode escapes anywhere (e.g.,
"\u003c"=>"<").
<?php
function js_uni_decode($s) {
return preg_replace('/\\\u([0-9a-f]{4})/ie', "chr(hexdec('\\1'))",
$s);
}
echo js_uni_decode("\u003c");
?>
Solution adapted from
http://weierophinney.net/matthew/archives/
133-PHP-decoding-of-Javascript-encodeURIComponent-values.html
http://php.net/manual/en/function.preg-replace.php