note 17835 added to function.substr-replace
| From: | stoned at theproject dot nu | Date: | Thu, 27 Dec 2001 23:48:37 +0000 |
| Subject: | note 17835 added to function.substr-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-23894@lists.php.net to get a copy of this message | ||
to replace the last occurence of a string in a string do this:
// This will remove the last occurence of test from $stack and make the new string $newstack
$stack = strrev("test is a test it is");
$needle = strrev("test ");
$needlelen = strlen($needle);
$needlepos = strpos($stack, $needle);
$newstack = strrev(substr_replace($stack, "", $needlepos, $needlelen));
now $newstack should be "test is a is"
might be useful... at least it was for me...
--
http://www.php.net/manual/en/function.substr-replace.php
http://master.php.net/manage/user-notes.php?action=edit+17835
http://master.php.net/manage/user-notes.php?action=delete+17835
http://master.php.net/manage/user-notes.php?action=reject+17835