Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>quite a tricky question to solve</p> <p>first off, the .*? will not match like you are expecting it to. </p> <p>its starts from the left finds the first match for &lt;a, then searches until it finds nextlink, which is essentially picking up the entire string. </p> <p>for that regex to work as you wanted, it would need to match from the righthand side first and work backwards through the string, finding the smallest (non-greedy) match</p> <p>i couldn't see any modifiers that would do this so i opted for a callback on each link, that will check and remove any link with nextlink in it</p> <pre><code>&lt;?php $string = '&lt;a href="http://www.mysite.com/test" class="prevlink"&gt;&amp;laquo; Previous&lt;/a&gt;&lt;a href=\'http://www.mysite.com/test/\' class=\'page\'&gt;1&lt;/a&gt;&lt;span class=\'current\'&gt;2&lt;/span&gt;&lt;a href=\'http://www.mysite.com/test/page/3/\' class=\'page\'&gt;3&lt;/a&gt;&lt;a href=\'http://www.mysite.com/test/page/4/\' class=\'page\'&gt;4&lt;/a&gt;&lt;a href="http://www.mysite.com/test/page/3/" class="nextlink"&gt;Next &amp;raquo;&lt;/a&gt;'; echo "RAW: $string\r\n\r\n"; $string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); echo "SRC: $string\r\n\r\n"; $string = preg_replace_callback( '@&amp;lt\;a.+?&amp;lt;/a&amp;gt;@', 'remove_nextlink', $string ); function remove_nextlink($matches) { // if you want to see each line as it works, uncomment this // echo "L: $matches[0]\r\n\r\n"; if (strpos($matches[0], 'nextlink') === FALSE) { return $matches[0]; // doesn't contain nextlink, put original string back } else { return ''; // contains nextlink, replace with blank } } echo "PROCESSED: $string\r\n\r\n"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload