문제

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!

도움이 되었습니까?

해결책 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.

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top