note 89207 modified in function.trim by thiago
| From: | thiago@php.net | Date: | Thu, 26 Feb 2009 14:29:11 +0000 |
| Subject: | note 89207 modified in function.trim by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-151166@lists.php.net to get a copy of this message | ||
If what you need is delete a string instead of character, this function could help you:
<?php
function trimString($input, $string){
$input = trim($input);
$startPattern = "/^($string)+/i";
$endPattern = "/($string)+$/i";
return trim(preg_replace($endPattern, '',
preg_replace($startPattern,'',$input)));
}
?>
Use:
<?php
echo trimString(" Hello world!. I said hello", "hello")
?>
Will return:
world!. I said
--was--
If what you need is delete a string instead of character, this function could helps you:
function trimString($input, $string){
$input = trim($input);
$startPattern = "/^($string)+/i";
$endPattern = "/($string)+$/i";
return trim(preg_replace($endPattern, '',
preg_replace($startPattern,'',$input)));
}
Use:
echo trimString(" Hello world!. I said hello", "hello")
Will return:
world!. I said
http://php.net/manual/en/function.trim.php