Pregunta

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&lt;p&gt;facebook_rubbish_here&lt;/p&gt;</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!

¿Fue útil?

Solución 2

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.

Otros consejos

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('~&lt;p&gt;.*?facebook.*?&lt;/p&gt;~', "", $rss_string);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top