Str_replace + regular expression

I have:

http://stackoverflow.com/questions/43242&cat=aa&id=342342 http://stackoverflow.com/questions/43242&cat=aa&body=434&id=232 http://stackoverflow.com/questions/43242&cat=aa&call=2323&id=14143434 

I would like to receive:

this link without parameter id:

 http://stackoverflow.com/questions/43242&cat=aa http://stackoverflow.com/questions/43242&cat=aa&body=434 http://stackoverflow.com/questions/43242&cat=aa&call=2323 

how to do it with php? str_replace + regex?

+4
source share
2 answers
 preg_replace('~&id=[0-9]+~', '', $str); 
+7
source

Use the appropriate function for this, not regular expressions, as URLs are not regular.

Then you have to split the query part that can be done using regular expressions, but I would like to split it and then filter out the identification part.

+3
source

All Articles