As I said, I then escaped the /p but it still did not work. I have just found out that the solution was that in preg_replace, the DOT does not match the newline character so I needed to use the 's' option.
preg_replace: regex does not work
-
13-07-2023 - |
Question
I am trying to remove a part with social links from an RSS feed with a RegEx like this:
preg_replace("/<p>.*?facebook.*?</p>/", "", $rss_string);
where $rss_string could be eg.
<description>important_content<p>facebook_rubbish_here</p></description>
At first it sais invalid modifier 'p'. Then I changed /p to \/p which caused it to run, but it does not find anything... What am I doing wrong? Am I not escaping something which I should?
Thank you!
Solution 2
OTHER TIPS
It is because you're using regex delimiter slash and your regex also contains slash. Either escape the forward slash or better use an alternative regex delimiter.
preg_replace('~<p>.*?facebook.*?</p>~', "", $rss_string);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow