这是我的代码:的preg_replace需要帮助的表达
$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;
我试图删除最后一个环节:
<a href="http://www.mysite.com/test/page/3/" class="nextlink">Next »</a>';
我的电流输出:
">Next »</a>
它消除了一切从头开始。 我希望它只能删除strpos,这是可能的preg_replace和如何? 谢谢。
与NEXTLINK任何链接尝试使用HTML(或XML)正则表达式可以是一个相当的交易。在你的情况下,你说要取代以....
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – 2011-08-31 08:34:05
@George '$string = preg_replace('@(<a).*?(nextlink).*?(</a>)@s', '', $string);' The output is empty. Great idea, I think my prex statment is wrong. could you take a look. Thanks – Muazam