note 87813 deleted from function.rtrim by thiago
| From: | thiago@php.net | Date: | Tue, 23 Dec 2008 16:26:06 +0000 |
| Subject: | note 87813 deleted from function.rtrim by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148478@lists.php.net to get a copy of this message | ||
Note Submitter: Chad Aebischer
----
In response to harmor:
Use preg_replace with the regex metacharacter '$'.
<?php
echo preg_replace('/(.*?)!$/', '$1', 'Hello World!!!'); //"Hello
World!!"
echo preg_replace('/(.*?)!*$/', '$1', 'Hello World!!!'); //"Hello
World"
?>
Use '^' for the left side.
<?php
echo preg_replace('/^!(.*?)/', '$1', '!!!Hello World');
//"!!Hello World"
echo preg_replace('/^!*(.*?)/', '$1', '!!!Hello World'); //"Hello
World"
?>