note 112749 added to function.str-replace
| From: | Anonymous | Date: | Fri, 19 Jul 2013 10:01:12 +0000 |
| Subject: | note 112749 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195674@lists.php.net to get a copy of this message | ||
@moostende at gmail dot com
If you want to remove all dashes but one from the string '-aaa----b-c-----d--e---f'
resulting in '-aaa-b-c-d-e-f', you CAN use str_replace !
<?php
function foo($str)
{
do {
$str = str_replace("--", "-", $str, $count);
} while ($count > 0);
return $str;
}
echo foo("-aaa----b-c-----d--e---f");
?>
This outputs the following:
-aaa-b-c-d-e-f
----
Server IP: 69.147.83.199
Probable Submitter: 82.241.75.215
----
Manual Page -- http://php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/112749
Del: integrated -- https://master.php.net/note/delete/112749/integrated
Del: useless -- https://master.php.net/note/delete/112749/useless
Del: bad code -- https://master.php.net/note/delete/112749/bad+code
Del: spam -- https://master.php.net/note/delete/112749/spam
Del: non-english -- https://master.php.net/note/delete/112749/non-english
Del: in docs -- https://master.php.net/note/delete/112749/in+docs
Del: other reasons-- https://master.php.net/note/delete/112749
Reject -- https://master.php.net/note/reject/112749
Search -- https://master.php.net/manage/user-notes.php