OSDN Git Service

Small update (Added UTF-8 Support)
[idb/iDB.git.git] / inc / misc / functions.php
1 <?php
2 /*
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the Revised BSD License.
5
6     This program is distributed in the hope that it will be useful,
7     but WITHOUT ANY WARRANTY; without even the implied warranty of
8     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9     Revised BSD License for more details.
10
11     Copyright 2004-2009 Cool Dude 2k - http://idb.berlios.de/
12     Copyright 2004-2009 Game Maker 2k - http://intdb.sourceforge.net/
13
14     $FileInfo: functions.php - Last Update: 6/07/2009 SVN 262 - Author: cooldude2k $
15 */
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="functions.php"||$File3Name=="/functions.php") {
18         require('index.php');
19         exit(); }
20 // Check the file names
21 function CheckFile($FileName) {
22 $File3Name = basename($_SERVER['SCRIPT_NAME']);
23 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
24         require('index.php');
25         exit(); }
26 return null; }
27 function CheckFiles($FileName) {
28 $File3Name = basename($_SERVER['SCRIPT_NAME']);
29 if ($File3Name==$FileName||$File3Name=="/".$FileName) {
30         return true; } }
31 CheckFile("functions.php");
32 require($SettDir['misc']."compression.php");
33 /* 
34 if ($_GET['act']=="DeleteSession") { @session_destroy(); }
35 if ($_GET['act']=="ResetSession") { @session_unset(); }
36 if ($_GET['act']=="NewSessionID") { @session_regenerate_id(); }
37 if ($_GET['act']=="PHPInfo") { @phpinfo(); exit(); }
38 if ($_GET['act']=="phpinfo") { @phpinfo(); exit(); }
39 if ($_GET['act']=="PHPCredits") { @phpcredits(); exit(); }
40 if ($_GET['act']=="phpcredits") { @phpcredits(); exit(); } 
41 */// Connect to mysql database
42 function ConnectMysql($sqlhost,$sqluser,$sqlpass,$sqldb,$retlink=false) {
43 if($retlink!==true) { $retlink = false; }
44 $StatSQL = @mysql_connect($sqlhost,$sqluser,$sqlpass);
45 $StatBase = @mysql_select_db($sqldb);
46 if (!$StatSQL) { return false; }
47 if (!$StatBase) { return false; }
48 if($retlink===true) { return $StatSQL; }
49 if($retlink===false) { return true; } }
50         $Names['RS'] = "Renee Sabonis";
51 define("_renee_", $Names['RS']);
52 // Change the title and gzip page
53 function change_title($new_title,$use_gzip="off",$gzip_type="gzip") {
54 global $Settings;
55 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
56 $output = @ob_get_clean();
57 $output = preg_replace("/<title>(.*?)<\/title>/i", "<title>".$new_title."</title>", $output);
58 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
59 $SessName = @session_name();
60 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
61 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
62 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
63 if($use_gzip!="on") {
64         echo $output; }
65 if($use_gzip=="on") {
66         if($gzip_type=="gzip") {
67         $goutput = gzencode($output); }
68         if($gzip_type=="deflate") {
69         $goutput = gzcompress($output); }
70         echo $goutput; } }
71 // Fix amp => (&) to &amp; and gzip page
72 function fix_amp($use_gzip="off",$gzip_type="gzip") {
73 global $Settings;
74 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
75 $output = @ob_get_clean();
76 /* Change Some PHP Settings Fix the &PHPSESSID to &amp;PHPSESSID */
77 $SessName = @session_name();
78 $output = preg_replace("/&PHPSESSID/", "&amp;PHPSESSID", $output);
79 $qstrcode = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
80 $output = str_replace($Settings['qstr'].$SessName, $qstrcode.$SessName, $output);
81 if($use_gzip!="on") {
82         echo $output; }
83 if($use_gzip=="on") {
84         if($gzip_type=="gzip") {
85         $goutput = gzencode($output); }
86         if($gzip_type=="deflate") {
87         $goutput = gzcompress($output); }
88         echo $goutput; } }
89         $Names['RJ'] = "Kazuki Przyborowski";
90 define("_rene_", $Names['RJ']);
91 // GZip page for faster download
92 function gzip_page($use_gzip="off",$gzip_type="gzip") {
93 global $Settings;
94 $output = @ob_get_clean();
95 if($gzip_type!="gzip") { if($gzip_type!="deflate") { $gzip_type = "gzip"; } }
96 if($use_gzip!="on") {
97         echo $output; }
98 if($use_gzip=="on") {
99         if($gzip_type=="gzip") {
100         $goutput = gzencode($output); }
101         if($gzip_type=="deflate") {
102         $goutput = gzcompress($output); }
103         echo $goutput; } }
104 $foo="bar"; $$foo="foo";
105 if(function_exists('mysql_set_charset')===false) {
106 function mysql_set_charset($charset) {
107         mysql_query("SET CHARACTER SET '".$charset."'");
108         mysql_query("SET NAMES '".$charset."'"); 
109         return true; } }
110 // SafeSQL Lite Source Code by Cool Dude 2k
111 // Make SQL Query's safe
112 function query($query_string,$query_vars) {
113    $query_array = array(array("%i","%I","%F","%S"),array("%d","%d","%f","%s"));
114    $query_string = str_replace($query_array[0], $query_array[1], $query_string);
115    if (get_magic_quotes_gpc()) {
116        $query_vars  = array_map("stripslashes", $query_vars); }
117    $query_vars = array_map("mysql_real_escape_string", $query_vars);
118    $query_val = $query_vars;
119 $query_num = count($query_val);
120 $query_i = 0;
121 while ($query_i < $query_num) {
122 $query_is = $query_i+1;
123 $query_val[$query_is] = $query_vars[$query_i];
124 ++$query_i; }
125    $query_val[0] = $query_string;
126    return call_user_func_array("sprintf",$query_val); }
127         $Names['KP'] = "Kazuki Przyborowski";
128 define("_kazuki_", $Names['KP']);
129 // Kill bad vars for some functions
130 function killbadvars($varname) {
131 $badphp1 = array('$'); $badphp2 = array(null);
132 $varname = str_replace($badphp1, $badphp2, $varname);
133 $varname = preg_replace("/(_SERVER|_ENV|_COOKIE|_SESSION)/i", null, $varname);
134 $varname = preg_replace("/(_GET|_POST|_FILES|_REQUEST|GLOBALS)/i", null, $varname);
135 $varname = preg_replace("/(HTTP_SERVER_VARS|HTTP_ENV_VARS)/i", null, $varname);
136 $varname = preg_replace("/(HTTP_COOKIE_VARS|HTTP_SESSION_VARS)/i", null, $varname);
137 $varname = preg_replace("/(HTTP_GET_VARS|HTTP_POST_VARS|HTTP_POST_FILES)/i", null, $varname);
138         return $varname; }
139 // Trying to fix this bug. ^_^
140 // http://xforce.iss.net/xforce/xfdb/49697
141 if(!isset($Settings['DefaultTheme'])) {
142         $Settings['DefaultTheme'] = "iDB"; }
143 $BoardTheme = $Settings['DefaultTheme'];
144 function chack_themes($theme) {
145 global $BoardTheme;
146 if(!isset($theme)) { $theme = null; }
147 require('settings.php');
148 $ckskindir = dirname(realpath("settings.php"))."/".$SettDir['themes'];
149 if ($handle = opendir($ckskindir)) { $dirnum = null;
150    while (false !== ($ckfile = readdir($handle))) {
151            if ($dirnum==null) { $dirnum = 0; }
152            if (file_exists($ckskindir.$ckfile."/info.php")) {
153                    if ($ckfile != "." && $ckfile != "..") {
154            include($ckskindir.$ckfile."/info.php");
155        $cktheme[$dirnum] =  $ckfile;
156            ++$dirnum; } } }
157    closedir($handle); asort($cktheme); }
158 $theme=preg_replace("/(.*?)\.\/(.*?)/", $BoardTheme, $theme);
159 if(!in_array($theme,$cktheme)||strlen($theme)>26) {
160         $theme = $BoardTheme; } return $theme; }
161 // Change the text to icons(smileys)
162 function text2icons($Text,$sqlt) {
163 global $Settings;
164 $reneequery=query("SELECT * FROM `".$sqlt."smileys`", array(null));
165 $reneeresult=mysql_query($reneequery);
166 $reneenum=mysql_num_rows($reneeresult);
167 $renees=0;
168 while ($renees < $reneenum) {
169 $FileName=mysql_result($reneeresult,$renees,"FileName");
170 $SmileName=mysql_result($reneeresult,$renees,"SmileName");
171 $SmileText=mysql_result($reneeresult,$renees,"SmileText");
172 $SmileDirectory=mysql_result($reneeresult,$renees,"Directory");
173 $ShowSmile=mysql_result($reneeresult,$renees,"Show");
174 $ReplaceType=mysql_result($reneeresult,$renees,"ReplaceCI");
175 if($ReplaceType=="on") { $ReplaceType = "yes"; }
176 if($ReplaceType=="off") { $ReplaceType = "no"; }
177 if($ReplaceType!="yes"||$ReplaceType!="no") { $ReplaceType = "no"; }
178 $Smile1 = $SmileText;
179 $Smile2 = '<img src="'.$SmileDirectory.''.$FileName.'" style="vertical-align: middle; border: 0px;" title="'.$SmileName.'" alt="'.$SmileName.'" />';
180 if($ReplaceType=="no") {
181 $Text = str_replace($Smile1, $Smile2, $Text); }
182 if($ReplaceType=="yes") {
183         $Smile1 = preg_quote($SmileText,"/");
184 $Text = preg_replace("/".$Smile1."/i",$Smile2,$Text); }
185 ++$renees; } return $Text; }
186 // Removes the bad stuff
187 function remove_bad_entities($Text) {
188 //HTML Entities Dec Version
189 $Text = preg_replace("/&#8238;/isU","",$Text);
190 $Text = preg_replace("/&#8194;/isU","",$Text);
191 $Text = preg_replace("/&#8195;/isU","",$Text);
192 $Text = preg_replace("/&#8201;/isU","",$Text);
193 $Text = preg_replace("/&#8204;/isU","",$Text);
194 $Text = preg_replace("/&#8205;/isU","",$Text);
195 $Text = preg_replace("/&#8206;/isU","",$Text);
196 $Text = preg_replace("/&#8207;/isU","",$Text);
197 //HTML Entities Hex Version
198 $Text = preg_replace("/&#x202e;/isU","",$Text);
199 $Text = preg_replace("/&#x2002;/isU","",$Text);
200 $Text = preg_replace("/&#x2003;/isU","",$Text);
201 $Text = preg_replace("/&#x2009;/isU","",$Text);
202 $Text = preg_replace("/&#x200c;/isU","",$Text);
203 $Text = preg_replace("/&#x200d;/isU","",$Text);
204 $Text = preg_replace("/&#x200e;/isU","",$Text);
205 $Text = preg_replace("/&#x200f;/isU","",$Text);
206 //HTML Entities Name Version
207 $Text = preg_replace("/&ensp;/isU","",$Text);
208 $Text = preg_replace("/&emsp;/isU","",$Text);
209 $Text = preg_replace("/&thinsp;/isU","",$Text);
210 $Text = preg_replace("/&zwnj;/isU","",$Text);
211 $Text = preg_replace("/&zwj;/isU","",$Text);
212 $Text = preg_replace("/&lrm;/isU","",$Text);
213 $Text = preg_replace("/&rlm;/isU","",$Text);
214 return $Text; }
215 // Remove the bad stuff
216 function remove_spaces($Text) {
217 $Text = preg_replace("/(^\t+|\t+$)/","",$Text);
218 $Text = preg_replace("/(^\n+|\n+$)/","",$Text);
219 $Text = preg_replace("/(^\r+|\r+$)/","",$Text);
220 $Text = preg_replace("/(\r|\n|\t)+/"," ",$Text);
221 $Text = preg_replace("/\s\s+/"," ",$Text);
222 $Text = preg_replace("/(^\s+|\s+$)/","",$Text);
223 $Text = @remove_bad_entities($Text);
224 return $Text; }
225 // Fix some chars
226 function fixbamps($text) {
227 $fixamps1 = array("&amp;copy;","&amp;reg;","&amp;trade;","&amp;quot;","&amp;amp;","&amp;lt;","&amp;gt;","&amp;(a|e|i|o|u|y)acute;","&amp;(a|e|i|o|u)grave;","&amp;(a|e|i|o|u)circ;","&amp;(a|e|i|o|u|y)uml;","&amp;(a|o|n)tilde;","&amp;aring;","&amp;aelig;","&amp;ccedil;","&amp;eth;","&amp;oslash;","&amp;szlig;","&amp;thorn;");
228 $fixamps2 = array("&copy;","&reg;","&trade;","&quot;","&amp;","&lt;","&gt;","&\\1acute;","&\\1grave;","&\\1circ;","&\\1uml;","&\\1tilde;","&aring;","&aelig;","&ccedil;","&eth;","&oslash;","&szlig;","&thorn;");
229 $ampnum = count($fixamps1); $ampi=0;
230 while ($ampi < $ampnum) {
231 $text = preg_replace("/".$fixamps1[$ampi]."/i", $fixamps2[$ampi], $text);
232 ++$ampi; }
233 $text = preg_replace("/&amp;#(x[a-f0-9]+|[0-9]+);/i", "&#$1;", $text);
234 return $text; }
235 // Get next id for stuff
236 function getnextid($tablepre,$table) {
237    $getnextidq = query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
238    $getnextidr = mysql_query($getnextidq);
239    $getnextid = mysql_fetch_assoc($getnextidr);
240    return $getnextid['Auto_increment'];
241    @mysql_free_result($getnextidr); }
242 function getnumrows($tablepre,$table) {
243    $getnextidq = query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
244    $getnextidr = mysql_query($getnextidq);
245    $getnextid = mysql_fetch_assoc($getnextidr);
246    return $getnextid['Rows'];
247    @mysql_free_result($getnextidr); }
248         $Names['K'] = "Katarzyna";
249 define("_katarzyna_", $Names['K']);
250 // Change Time Stamp to a readable time
251 function GMTimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
252 $TCHour = date("H",$timestamp);
253 $TCMinute = date("i",$timestamp);
254 $TCSecond = date("s",$timestamp);
255 $TCMonth = date("n",$timestamp);
256 $TCDay = date("d",$timestamp);
257 $TCYear = date("Y",$timestamp);
258 $dstake = null;
259 if(!is_numeric($minoffset)) { $minoffset = "00"; }
260 $ts_array = explode(":",$offset);
261 if(count($ts_array)!=2) {
262         if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
263         if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
264         $offset = $ts_array[0].":".$ts_array[1]; }
265 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
266 if($ts_array[0]>12) { $ts_array[0] = "12"; $offset = $ts_array[0].":".$ts_array[1]; }
267 if($ts_array[0]<-12) { $ts_array[0] = "-12"; $offset = $ts_array[0].":".$ts_array[1]; }
268 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
269 if($ts_array[1]>59) { $ts_array[1] = "59"; $offset = $ts_array[0].":".$ts_array[1]; }
270 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
271 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
272 //$tsa['minute'] = $tsa['minute'] + $minoffset;
273 if($dst!="on"&&$dst!="off") { $dst = "off"; }
274 if($dst=="on") { if($dstake!="done") { 
275         $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
276 $TCHour = $TCHour + $tsa['hour'];
277 $TCMinute = $TCMinute + $tsa['minute'];
278 return date($format,mktime($TCHour,$TCMinute,$TCSecond,$TCMonth,$TCDay,$TCYear)); }
279         $Names['CK'] = "Christine";
280 define("_christine_", $Names['CK']);
281 // Change Time Stamp to a readable time
282 function TimeChange($format,$timestamp,$offset,$minoffset=null,$dst=null) {
283 return GMTimeChange($format,$timestamp,$offset,$minoffset,$dst); }
284 // Make a GMT Time Stamp
285 function GMTimeStamp() {
286 $GMTHour = gmdate("H");
287 $GMTMinute = gmdate("i");
288 $GMTSecond = gmdate("s");
289 $GMTMonth = gmdate("n");
290 $GMTDay = gmdate("d");
291 $GMTYear = gmdate("Y");
292 return mktime($GMTHour,$GMTMinute,$GMTSecond,$GMTMonth,$GMTDay,$GMTYear); }
293 function GMTimeStampS() { return time() - date('Z', time()); }
294 function GMTimeGet($format,$offset,$minoffset=null,$dst=null) { 
295         return GMTimeChange($format,GMTimeStamp(),$offset,$minoffset,$dst); }
296 function GMTimeGetS($format,$offset,$minoffset=null,$dst=null) {
297 $dstake = null;
298 if(!is_numeric($offset)) { $offset = "0"; }
299 if(!is_numeric($minoffset)) { $minoffset = "00"; }
300 $ts_array = explode(":",$offset);
301 if(count($ts_array)!=2) {
302         if(!isset($ts_array[0])) { $ts_array[0] = "0"; }
303         if(!isset($ts_array[1])) { $ts_array[1] = "00"; }
304         $offset = $ts_array[0].":".$ts_array[1]; }
305 if(!is_numeric($ts_array[0])) { $ts_array[0] = "0"; }
306 if($ts_array[0]>12) { $ts_array[0] = "12"; $offset = $ts_array[0].":".$ts_array[1]; }
307 if($ts_array[0]<-12) { $ts_array[0] = "-12"; $offset = $ts_array[0].":".$ts_array[1]; }
308 if(!is_numeric($ts_array[1])) { $ts_array[1] = "00"; }
309 if($ts_array[1]>59) { $ts_array[1] = "59"; $offset = $ts_array[0].":".$ts_array[1]; }
310 if($ts_array[1]<0) { $ts_array[1] = "00"; $offset = $ts_array[0].":".$ts_array[1]; }
311 $tsa = array("offset" => $offset, "hour" => $ts_array[0], "minute" => $ts_array[1]);
312 //$tsa['minute'] = $tsa['minute'] + $minoffset;
313 if($dst!="on"&&$dst!="off") { $dst = "off"; }
314 if($dst=="on") { if($dstake!="done") { 
315         $dstake = "done"; $tsa['hour'] = $tsa['hour']+1; } }
316 return date($format,mktime(gmdate('h')+$tsa['hour'],gmdate('i')+$tsa['minute'],gmdate('s'),gmdate('n'),gmdate('j'),gmdate('Y'))); }
317 // Get Server offset
318 function GetSeverZone() {
319 $TestHour1 = date("H");
320 @putenv("OTZ=".@getenv("TZ"));
321 @putenv("TZ=GMT");
322 $TestHour2 = date("H");
323 @putenv("TZ=".@getenv("OTZ"));
324 $TestHour3 = $TestHour1-$TestHour2;
325 return $TestHour3; }
326 function SeverOffSet() {
327 $TestHour1 = date("H");
328 $TestHour2 = gmdate("H");
329 $TestHour3 = $TestHour1-$TestHour2;
330 return $TestHour3; }
331 function SeverOffSetNew() {
332 return gmdate("g",mktime(0,date("Z"))); }
333 function gmtime() { return time() - (int) date('Z'); }
334 function file_get_source($filename,$return = FALSE) {
335 // Acts like highlight_file();
336 $phpsrc = file_get_contents($filename);
337 $phpsrcs = highlight_string($phpsrc,$return);
338 return $phpsrcs; }
339 function valid_get_source($filename) {
340 $phpsrcs = file_get_source($filename,TRUE);
341 // Change font tag to span tag for valid xhtml
342 $phpsrcs = preg_replace("/\<font color=\"(.*?)\"\>/i", "<span style=\"color: \\1;\">", $phpsrcs);
343 $phpsrcs = preg_replace("/\<\/font>/i", "</span>", $phpsrcs);
344 return $phpsrcs; }
345 function GetUserName($idu,$sqlt) {
346 $gunquery = query("SELECT * FROM `".$sqlt."members` WHERE `id`=%i", array($idu));
347 $gunresult=mysql_query($gunquery);
348 $gunnum=mysql_num_rows($gunresult);
349 if($gunnum>0){
350 $UsersName=mysql_result($gunresult,0,"Name"); }
351 @mysql_free_result($gunresult);
352 return $UsersName; }
353 // hmac hash function
354 function hmac($data,$key,$hash='sha1',$blocksize=64) {
355   if (strlen($key)>$blocksize) {
356   $key=pack('H*',$hash($key)); }
357   $key=str_pad($key, $blocksize, chr(0x00));
358   $ipad=str_repeat(chr(0x36),$blocksize);
359   $opad=str_repeat(chr(0x5c),$blocksize);
360   return $hash(($key^$opad).pack('H*',$hash(($key^$ipad).$data))); }
361 // b64hmac hash function
362 function b64e_hmac($data,$key,$extdata,$hash='sha1',$blocksize=64) {
363         $extdata2 = hexdec($extdata); $key = $key.$extdata2;
364   return base64_encode(hmac($data,$key,$hash,$blocksize).$extdata); }
365 // salt hmac hash function
366 function salt_hmac($size1=4,$size2=6) {
367 $hprand = rand(4,6); $i = 0; $hpass = "";
368 while ($i < $hprand) {
369 $hspsrand = rand(1,2);
370 if($hspsrand!=1&&$hspsrand!=2) { $hspsrand=1; }
371 if($hspsrand==1) { $hpass .= chr(rand(48,57)); }
372 if($hspsrand==2) { $hpass .= chr(rand(65,70)); }
373 ++$i; } return $hpass; }
374 /* is_empty by M at http://us2.php.net/manual/en/function.empty.php#74093 */
375 function is_empty($var) {
376     if (((is_null($var) || rtrim($var) == "") &&
377                 $var !== false) || (is_array($var) && empty($var))) {
378         return true; } else { return false; } }
379 // Hash two times with md5 and sha1
380 function PassHash2x($Text) {
381 $Text = md5($Text);
382 $Text = sha1($Text);
383 return $Text; }
384 // Hash two times with hmac-md5 and hmac-sha1
385 function PassHash2x2($data,$key,$extdata,$blocksize=64) {
386 $extdata2 = hexdec($extdata); $key = $key.$extdata2;
387 $Text = hmac($data,$key,"md5").$extdata; 
388 $Text = hmac($Text,$key,"sha1").$extdata;
389 return base64_encode($Text); }
390 function cp($infile,$outfile,$mode="w") { 
391    $contents = file_get_contents($infile);
392    $cpfp = fopen($outfile,$mode);
393    fwrite($cpfp, $contents);
394    fclose($cpfp);
395    return true; }
396 /* str_ireplace for PHP below ver. 5 updated // 
397 //       by Kazuki Przyborowski - Cool Dude 2k      //
398 //      and upaded by Kazuki Przyborowski again     */
399 if(!function_exists('str_ireplace')) {
400 function str_ireplace($search,$replace,$subject) {
401 if(!is_array($search)&&is_array($replace)) {
402         $search = array($search); }
403 if(is_array($search)&&!is_array($replace)) {
404         $replace = array($replace); }
405 if(is_array($search)&&is_array($replace)) {
406         $sc=count($search); $rc=count($replace); $sn=0;
407         if($sc!=$rc) { return false; }
408 while ($sc > $sn) {
409         $search[$sn] = preg_quote($search[$sn], "/");
410         $subject = preg_replace("/".$search[$sn]."/i", $replace[$sn], $subject);
411         ++$sn; } }
412 if(!is_array($search)&&!is_array($replace)) {
413 $search = preg_quote($search, "/");
414 $subject = preg_replace("/".$search."/i", $replace, $subject); }
415 return $subject; } }
416 /*   Adds mysql_set_charset to PHP below Ver. 5.2.3 - by: Janez R.      // 
417 //   http://us.php.net/manual/en/function.mysql-set-charset.php#77565   */
418 if (!function_exists('mysql_set_charset')) {
419   function mysql_set_charset($charset) {
420     return mysql_query("set names $charset"); } }
421 /*   Adds httponly to PHP below Ver. 5.2.0   // 
422 //       by Kazuki Przyborowski - Cool Dude 2k      */
423 function http_set_cookie($name,$value=null,$expire=null,$path=null,$domain=null,$secure=false,$httponly=false) {
424         $mkcookie = null; $expireGMT = null;
425         if(!isset($name)) { echo "Error: You need to enter a name for cookie."; return false; }
426         if(!isset($expire)) { echo "Error: You need to enter a time for cookie to expire."; return false; }
427         $expireGMT = gmdate("D, d-M-Y H:i:s \G\M\T", $expire);
428         if(!isset($value)) { $value = null; }
429         if(!isset($httponly)||$httponly==false) {
430         setcookie($name, $value, $expire, $path, $domain, $secure); return true; }
431         if(version_compare(PHP_VERSION,"5.2.0",">=")&&$httponly==true) {
432         setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); return true; }
433         if(version_compare(PHP_VERSION,"5.2.0","<")&&$httponly==true) {
434         $mkcookie = "Set-Cookie: ".rawurlencode($name)."=".rawurlencode($value);
435         $mkcookie = $mkcookie."; expires=".$expireGMT;
436         if(isset($path)&&$path!=null) { $mkcookie = $mkcookie."; path=".$path; }
437         if(isset($domain)&&$domain!=null) { $mkcookie = $mkcookie."; domain=".$domain; }
438         if(isset($secure)&&$secure===true) { $mkcookie = $mkcookie."; secure"; }
439         if(isset($httponly)&&$httponly===true) { $mkcookie = $mkcookie."; HttpOnly"; }
440 header($mkcookie, false); return true; } }
441 $foobar="fubar"; $$foobar="foobar";
442 // Debug info
443 function dump_included_files() {        return var_dump(get_included_files()); }
444 function count_included_files() {       return count(get_included_files()); }
445 function dump_extensions() {    return var_dump(get_loaded_extensions()); }
446 function count_extensions() {   return count(get_loaded_extensions()); }
447 ?>