/*
* 等同escape
*
*/
function phpEscape($str,$encode="") {
if ($encode=="" && !(function_exists("mb_detect_encoding"))) {
echo "error You must enter the string's encoding or extend the php for mb_string";
return ;
}
elseif($encode=="") {
//echo "Use mb_string function to detect the string's encoding <br/>";
$encode = mb_detect_encoding($str);
}
$chars = preg_split('//', $str, -1 ) ; //pr($chars);
$n = count( $chars )-1 ;
for($i=1;$i<$n ;$i++ ) {
$char = $chars[$i];
$ord = ord( $char ); //echo $ord . " -- ".chr($ord)." -- $i<br>";
if( $ord<=0x7F){
$ar .= rawurlencode( $char );
}elseif ($ord<0xE0) {
$ar .= "%u".bin2hex( iconv( $encode,"UCS-2",$chars[$i].$chars[$i+1] ) );
$i++;
}elseif ($ord<0xF0) {
$ar .= "%u".bin2hex( iconv( $encode,"UCS-2",$chars[$i].$chars[$i+1] ) );
$i++;
}
}//foreach
return $ar;
}
* 等同escape
*
*/
function phpEscape($str,$encode="") {
if ($encode=="" && !(function_exists("mb_detect_encoding"))) {
echo "error You must enter the string's encoding or extend the php for mb_string";
return ;
}
elseif($encode=="") {
//echo "Use mb_string function to detect the string's encoding <br/>";
$encode = mb_detect_encoding($str);
}
$chars = preg_split('//', $str, -1 ) ; //pr($chars);
$n = count( $chars )-1 ;
for($i=1;$i<$n ;$i++ ) {
$char = $chars[$i];
$ord = ord( $char ); //echo $ord . " -- ".chr($ord)." -- $i<br>";
if( $ord<=0x7F){
$ar .= rawurlencode( $char );
}elseif ($ord<0xE0) {
$ar .= "%u".bin2hex( iconv( $encode,"UCS-2",$chars[$i].$chars[$i+1] ) );
$i++;
}elseif ($ord<0xF0) {
$ar .= "%u".bin2hex( iconv( $encode,"UCS-2",$chars[$i].$chars[$i+1] ) );
$i++;
}
}//foreach
return $ar;
}