开发者

Regular Expressions - Insert Multiple Times

开发者 https://www.devze.com 2023-01-15 02:30 出处:网络
Same for example I have this: 开发者_运维技巧Hello world!! Hello all! I want replace each \"!\" with a period for example.With PHP.How would I do that?Don\'t you think str_replace would suffice?

Same for example I have this:

开发者_运维技巧Hello world!!
Hello all!

I want replace each "!" with a period for example. With PHP. How would I do that?


Don't you think str_replace would suffice?

$str = str_replace('!','.',$str);


preg_replace('#\!+#s', 'what_ever_you_want', $subject)


I figured out out. I cannot believe I didn't see this before. ! is a metacharacter so I need a '\' before it. That's why it wasn't working. Thanks.

0

精彩评论

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