// Copyright: Copyright (C) 2003-2007 Pristine Communications // addslashes_like: addslashes() in like version // Removed. Replaced with sql_esclike() // addslashes_re: addslashes() in regular expression version function addslashes_re($s) { // Cache the result static $cache = array(); // Return the cache if (array_key_exists($s, $cache)) { return $cache[$s]; } $r = $s; $r = preg_replace("/\\\\/", "\\\\\\\\", $r); $r = preg_replace("/(\W)/", "\\\\$1", $r); if (preg_match("/^\w/", $s)) { $r = "[[:<:]]" . $r; } if (preg_match("/\w$/", $s)) { $r = $r . "[[:>:]]"; } $cache[$s] = $r; return $r; } // addslashes_re_php: addslashes() in PHP preg_* version function addslashes_re_php($s) { // Cache the result static $cache = array(); // Return the cache if (array_key_exists($s, $cache)) { return $cache[$s]; } $r = $s; // ASCII punctuations area $r = preg_replace("/([\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E])/", "\\\\$1", $r); $r = str_replace("\n", "\\n", $r); $r = str_replace("\r", "\\r", $r); $r = str_replace("\t", "\\t", $r); // Disabled. It may not always be a word piece. // To be designed a better handling method on this issue. //if (preg_match("/^\w/", $s)) { // $r = "\\b" . $r; //} //if (preg_match("/\w$/", $s)) { // $r = $r . "\\b"; //} $cache[$s] = $r; return $r; } ?>