views:

62

answers:

3

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 should use regex?

+3  A: 

yes,

 preg_replace('~\?myuser=\d+~', '', $string);
stereofrog
+2  A: 

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);
Boldewyn
A: 
$str = preg_replace("/\?myuser=(\d+)/iU","",$yourstring);
Mannaz
`\n` is a new line. `\d` are numbers.
Boldewyn
...which is easy to remember if you stop thinking of _numbers_ but instead think of it as _digits_
dbemerlin