5 // Function only available PHP >=5.5.0
6 if(!function_exists('imagepalettetotruecolor')) {
7 function imagepalettetotruecolor(&$src) {
8 if(imageistruecolor($src)) {
11 $dst = imagecreatetruecolor(imagesx($src), imagesy($src));
13 imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src));
23 // Replace a section of an array with the elements in reverse
24 function array_splice_reverse(&$arr, $offset, $length) {
25 $tmp = (array_reverse(array_slice($arr, $offset, $length)));
26 array_splice($arr, $offset, $length, $tmp);
31 function urldecode_parts($url) {
34 if (preg_match('/[?]/',$url)) {
35 $bits = preg_split('/[?]/',$url,2);
39 $file = rawurldecode($file);
40 $query = urldecode($query);
45 function _strspn($str1, $str2, $start=null, $length=null) {
46 $numargs = func_num_args();
48 return strspn($str1, $str2);
50 else if ($numargs == 3) {
51 return strspn($str1, $str2, $start);
54 return strspn($str1, $str2, $start, $length);
59 function _strcspn($str1, $str2, $start=null, $length=null) {
60 $numargs = func_num_args();
62 return strcspn($str1, $str2);
64 else if ($numargs == 3) {
65 return strcspn($str1, $str2, $start);
68 return strcspn($str1, $str2, $start, $length);
72 function _fgets (&$h, $force=false) {
73 $startpos = ftell($h);
75 if ($force && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) {
77 fseek($h,$startpos+
strlen($s));
83 // For PHP4 compatability
84 if(!function_exists('str_ireplace')) {
85 function str_ireplace($search,$replace,$subject) {
86 $search = preg_quote($search, "/");
87 return preg_replace("/".$search."/i", $replace, $subject);
90 if(!function_exists('htmlspecialchars_decode')) {
91 function htmlspecialchars_decode ($str) {
92 return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
96 function PreparePreText($text,$ff='//FF//') {
97 $text = htmlspecialchars($text);
98 if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); }
99 return ('<pre>'.$text.'</pre>');
102 if(!function_exists('strcode2utf')){
103 function strcode2utf($str,$lo=true) {
104 //converts all the &#nnn; and &#xhhh; in a string to Unicode
107 $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_lo_callback', $str);
108 $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_lo_callback', $str);
111 $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_callback', $str);
112 $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_callback', $str);
117 function code2utf_callback($matches) {
118 return code2utf($matches[1], 0);
120 function code2utf_lo_callback($matches) {
121 return code2utf($matches[1], 1);
123 function codeHex2utf_callback($matches) {
124 return codeHex2utf($matches[1], 0);
126 function codeHex2utf_lo_callback($matches) {
127 return codeHex2utf($matches[1], 1);
131 if(!function_exists('code2utf')){
132 function code2utf($num,$lo=true){
133 //Returns the utf string corresponding to the unicode value
135 if ($lo) return chr($num);
136 else return '&#'.$num.';';
138 if ($num<2048) return chr(($num>>6)+
192).chr(($num&63)+
128);
139 if ($num<65536) return chr(($num>>12)+
224).chr((($num>>6)&63)+
128).chr(($num&63)+
128);
140 if ($num<2097152) return chr(($num>>18)+
240).chr((($num>>12)&63)+
128).chr((($num>>6)&63)+
128) .chr(($num&63)+
128);
146 if(!function_exists('codeHex2utf')){
147 function codeHex2utf($hex,$lo=true){
149 if (($num<128) && !$lo) return '&#x'.$hex.';';
150 return code2utf($num,$lo);