开发者

How can I replace ?myuser=number with an empty string in PHP

开发者 https://www.devze.com 2022-12-22 20:06 出处:网络
How can I replace a string containing a lot of ?myuser=12122 ?myuser=5457 ... with empty string so that it doesn\'t show ?myuser=number inside the string?

How can I replace a string containing a lot of ?myuser=12122 ?myuser=5457 ... with empty string so that it doesn't show ?myuser=number inside the string?

I think I开发者_StackOverflow should use regex?


yes,

 preg_replace('~\?myuser=\d+~', '', $string);


The question mark is a special character in regular expressions, so you must quote it. Apart from that, it's quite straight forward:

$result = preg_replace('/\?myuser=[0-9]+/', '', $source);


$str = preg_replace("/\?myuser=(\d+)/iU","",$yourstring);
0

精彩评论

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