I got this
$description = '<p>text1</p><p>text2</p><p>text3</p><p>text4</p><p>textn</p>'
I want to remove only what comes after <p>text3</p>
My result would be:
$description = '<p>text1</p><p>text2</p><p>text3</p>'
My guess is that we need to use preg_replace
with some regex but I can't manage to write a working one.
[^<]*
){3}).*` as a group and then replace with `\1` – User Dec 31 '12 at 19:50[^<]*
){3}).*/i','$1', $description);` Obviously Wistar there are a number of problems with using regex but it might be okay for your use-case. Just depends. Best thing would be to encapsulate the functionality in a function and then you can change the implementation as needed. – User Dec 31 '12 at 20:07