[英]How can I replace ?myuser=number with an empty string in PHP
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? 如何用空字符串替换包含大量
?myuser=12122
?myuser=5457
...
字符串,以便它不会在字符串中显示?myuser=number
?
I think I should use regex? 我想我应该使用正则表达式?
是,
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.