Replace Multiple "-" PHP [duplicate]
Possible Du开发者_如何学编程plicate:
PHP Preg-Replace more than one underscore
Hi, I'm just wondering how I can replace 2 or more - signs in a string with just one in PHP.
So like
1-2---3--4
would go to
1-2-3-4
Thanks :)
Use preg_replace:
$str = preg_replace('/-+/', '-', $str);
No need regex
$text="1-2---3--4";
$s = implode("-",array_filter ( explode("-",$text) )) ;
print_r($s);
精彩评论