开发者

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 receive:

this link without parameter id:

http://stackoverflow.com开发者_JAVA百科/questions/43242&cat=aa
http://stackoverflow.com/questions/43242&cat=aa&body=434
http://stackoverflow.com/questions/43242&cat=aa&call=2323

how this make with PHP? str_replace + regular expression?


preg_replace('~&id=[0-9]+~', '', $str);


Use the appropriate function for this, not regular expressions since URL's aren't regular.

You should then split the query part, which can be done with regular expressions, but I'd like to split on & and then filter out the ID part.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜