note 89207 deleted from function.trim by hholzgra

From: Date: Thu, 02 Aug 2012 12:29:36 +0000
Subject: note 89207 deleted from function.trim by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189664@lists.php.net to get a copy of this message
Note Submitter: dev dot ivangc at gmail dot com ---- 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

« previous php.notes (#189664) next »