summaryrefslogtreecommitdiff
path: root/includes/inc_utils.php
blob: 071d8b0483f408930d59fe937c6d34811d0b6d40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
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))
	{
		$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;
}


?>