2
0
forked from Wavyzz/dolibarr

Fix: Add an unsecape function to decode javascript escape

encoding. This also fix ecm for cyrillic chars.
This commit is contained in:
Laurent Destailleur
2012-06-24 19:32:19 +02:00
parent 0a75367a74
commit 018cafe92c
8 changed files with 234 additions and 8 deletions

View File

@@ -24,6 +24,45 @@
* This file contains all rare functions.
*/
/**
* Same function than javascript unescape() function but in PHP.
*
* @param string $sourcetodecode String to decode
* @return
*/
function jsUnEscape($source)
{
$decodedStr = "";
$pos = 0;
$len = strlen ($source);
while ($pos < $len) {
$charAt = substr ($source, $pos, 1);
if ($charAt == '%') {
$pos++;
$charAt = substr ($source, $pos, 1);
if ($charAt == 'u') {
// we got a unicode character
$pos++;
$unicodeHexVal = substr ($source, $pos, 4);
$unicode = hexdec ($unicodeHexVal);
$entity = "&#". $unicode . ';';
$decodedStr .= utf8_encode ($entity);
$pos += 4;
}
else {
// we have an escaped ascii character
$hexVal = substr ($source, $pos, 2);
$decodedStr .= chr (hexdec ($hexVal));
$pos += 2;
}
} else {
$decodedStr .= $charAt;
$pos++;
}
}
return dol_html_entity_decode($decodedStr, ENT_COMPAT);
}
/**
* Return list of modules directories