I have content which contains many paragraphs, but I want to dynamically remove the last one. The last paragraph follows a similar pattern with static text and dynamic text. It looks like this : "This story * dynamic text here* was inspired by *varying text here * "
The words "This story" and "was inspired by" don't change.
I would like to use preg_replace in php wordpress to programmatically remove that last paragraph. I need help about the proper pattern to use to find and select that text, so that it is replaced.
Here's a sample of the $content
<p>First paragraph of text</p>
<p>Second paragraph</p>
<p>This story <a rel="nofollow" href="http://example.com/inspiration">My Inspiration</a> was inspired by <a rel="nofollow" href="http://example.com">NiceOne</a>.</p>
I tried this, but it deletes the whole content.
$pattern = '^.*was inspired by.*$' ;
$replacement = '';
$new_content = preg_replace($pattern, $replacement, $content);
Thanks.