0

I am planning to use preg_replace to remove some unwanted stuff from dynamic string

$mystring:
<ul><li><a href="http://www.url.com/wiki/How_to_fix_erection_problems_after_prostate_surgery&amp;diff=335&amp;oldid=prev">How to fix erection problems after prostate surgery</a></li>
<li><a href="http://www.url.com/wiki/Wikipenis:Community_Portal&amp;diff=334&amp;oldid=prev">Wikipenis:Community Portal</a></li>
</ul>


This string is generated from an RSS reader. (The url has obviously been replaced to make sure no one thinks this is a spam post)

What I need to do is figure out a way to go through the string and remove the "&amp;diff=335&amp;oldid=prev" and the "&amp;diff=334&amp;oldid=prev"
I can not just use str_replace() because those two constantly change. However I assume it is possible with a regular expressions I just don't know regular expressions well enough to write one...but basically it needs to say something like:
preg_replace("&amp;diff=" and all characters in the middle to "=prev", "", $mystring);

1
Contributor
2
Replies
4
Views
7 Years
Discussion Span
Last Post by SerjSagan
0

I got this:
echo preg_replace("\&amp;diff.+?=prev", "", $mystring);

using this tool:
http://gskinner.com/RegExr/

But that gives me this error:
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in /home/enhancement/www/www/index.htm on line 134

Edited by SerjSagan: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.