From ca4074913b2ad21eac4987df1349fc386fc9b9a7 Mon Sep 17 00:00:00 2001 From: TheTroll Date: Thu, 25 Feb 2010 14:17:28 +0100 Subject: Changed converted strings format --- includes/inc_utils.php | 97 +++++++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/includes/inc_utils.php b/includes/inc_utils.php index 541c35b..071d8b0 100755 --- a/includes/inc_utils.php +++ b/includes/inc_utils.php @@ -1,50 +1,59 @@ 128){ - if(($c >= 254)) return false; - elseif($c >= 252) $bits=6; - elseif($c >= 248) $bits=5; - elseif($c >= 240) $bits=4; - elseif($c >= 224) $bits=3; - elseif($c >= 192) $bits=2; - else return false; - if(($i+$bits) > $len) return false; - while($bits > 1){ - $i++; - $b=ord($str[$i]); - if($b < 128 || $b > 191) return false; - $bits--; - } - } - } - return true; +function is_utf8($str) +{ + $c=0; $b=0; + $bits=0; + $len=strlen($str); + for($i=0; $i<$len; $i++) + { + $c=ord($str[$i]); + if($c > 128) + { + if(($c >= 254)) return false; + elseif($c >= 252) $bits=6; + elseif($c >= 248) $bits=5; + elseif($c >= 240) $bits=4; + elseif($c >= 224) $bits=3; + elseif($c >= 192) $bits=2; + else return false; + if(($i+$bits) > $len) return false; + while($bits > 1) + { + $i++; + $b=ord($str[$i]); + if($b < 128 || $b > 191) return false; + $bits--; + } + } + } + return true; } -function php2js ($var) { - if (is_array($var)) { - $res = "["; - $array = array(); - foreach ($var as $a_var) { - $array[] = php2js($a_var); - } - return join(",", $array); - } - elseif (is_bool($var)) { - return $var ? "true" : "false"; - } - elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)) { - return $var; - } - elseif (is_string($var)) { - return "\"" . addslashes(stripslashes($var)) . "\""; - } - // autres cas: objets, on ne les gère pas - return FALSE; +function php2js ($var) +{ + if (is_array($var)) + { + $array = array(); + + foreach ($var as $a_var) + $array[] = php2js($a_var); + + return str_replace("\"", "'", join(",", $array)); + + + } + + elseif (is_bool($var)) + return ($var ? "true" : "false"); + + elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)) + return $var; + + elseif (is_string($var)) + return "\"" . addslashes(stripslashes($var)) . "\""; + + else + return false; } -- cgit v1.2.3