note 89751 modified in function.trim by danbrown
| From: | danbrown@php.net | Date: | Sat, 21 Mar 2009 13:10:26 +0000 |
| Subject: | note 89751 modified in function.trim by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152255@lists.php.net to get a copy of this message | ||
small fix for the trimString function to proof against slash and backslash:
<?php
function trimString($input, $string){
$input = trim($input);
$string = str_replace("\\", "\\\\", $string);
$string = str_replace('/', '\\/', $string);
$startPattern = "/^($string)+/i";
$endPattern = "/($string)+$/i";
return trim(preg_replace($endPattern, '',
preg_replace($startPattern,'',$input)));
}
?>
--was--
small fix for the trimString function to proof against slash and backslash:
function trimString($input, $string){
$input = trim($input);
$string = str_replace("\\", "\\\\", $string);
$string = str_replace('/', '\\/', $string);
$startPattern = "/^($string)+/i";
$endPattern = "/($string)+$/i";
return trim(preg_replace($endPattern, '',
preg_replace($startPattern,'',$input)));
}
http://php.net/manual/en/function.trim.php