I have a feed that I need to clean up. I'm not too experienced with all of the string replace functions so I was hoping you guys might be able to help. Right now I have some paragraphs that need to be removed. The paragraphs have a "????" in them and they are each separated by a <p>. Is there any way to remove a paragraph if it contains the four question marks in a row?
Here is the script code. All blocks started with tag <p>, ended with </p> and contained "????" are removed from $s: $s = preg_replace('/<p>.*?\?{4}.*?<\/p>/si','',$s); PHP:
hey wmtips, ive been doing php for a while, and learned abotu preg_replace and other regular expressions, but never really actually understood how they worked. where did you learn how to use them? Thanks
Just learn the syntax. One of my favourite tutorials (for .NET, but very similar to php) is here. I also would recommend to download recently published Regular Expressions Cheat Sheet.
Thanks for the code wmtips. I can't believe I posted that 5 days ago...feels like 5 hours ago. I'm still having a bit of a problem, here's what's up: This displays the third paragraph only. I think it sees the first "<p>" instead of the one closest to the "????" and replaces everything. Any ideas?
Hmm, yes I was not right.. Ok, it's a bit harder. If we assume that paragraphs can contain other tags, the regex will be: $s = preg_replace('/<p>((?!<p>).)*?\?{4}.*?<\/p>/si','', $s); PHP: If paragraphs do not contain any html tags, regex can be simplier..