This is my code:
$string = '<a href="http://www.mysite.com/test" class="prevlink">« Previous</a><a href=\'http://www.mysite.com/test/\' class=\'page\'>1</a><span class=\'current\'>2</span><a href=\'http://www.mysite.com/test/page/3/\' class=\'page\'>3</a><a href=\'http://www.mysite.com/test/page/4/\' class=\'page\'>4</a><a href="http://www.mysite.com/test/page/3/" class="nextlink">Next »</a>';
$string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8');
$string = preg_replace('@(<a).*?(nextlink)@s', '', $string);
echo $string;
I am trying to remove the last link:
<a href="http://www.mysite.com/test/page/3/" class="nextlink">Next »</a>';
My current output:
">Next »</a>
It removes everything from the start. I want it to remove only the one with strpos, is this possible with preg_replace and how? Thanks.