开发者

Replace Multiple "-" PHP [duplicate]

This question already has answers here: Closed 12 years ago.

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜