replace replacing anchor text
Having issues wish a preg_replace function.
I am formatting a breadcrumb which the php is ioncubed so I am having to preg_replace to remove part of the breadcrumb.
I have a breadcrumb that looks like
<ul>
<li><a href="mylink1.html">Link 1</a><i class="fa fa-angle-right"></i></li>
<li><a href="mylink2.html">Link 2</a><i class="fa fa-angle-right"></i></li>
<li><a href="mylink3.html">Link 3</a></li>
</ul>
What I want to do is completely remove
<li><a href="#">Link 2</a><i class="fa fa-angle-right"></i></li>
My Original thoughts were to just str_replace
<li><a href="#">Link 2</a><i class="fa fa-angle-right"></i></li>
with nothing however the link can vary depending on the language file loaded.
I then thought about preg_replace the content of the url as the href is constant however I have absolutley no experiance with PHP and all attempts I have tried give random responses.
I'm hoping someone can help with the preg_replace or even if there is a better way to remove the line.
So far Ive tried
$str = '<li><a href="mylink.php">Link 2</a></li>';
$preg_replace = preg_replace('<li><a href="mylink.php">(.*)','placeholder',$str);
echo $preg_replace;
Thanks
You have to bound your regex, typically with /
. You also might want to include the closing tag or your regex will match more than you want
$preg_replace = preg_replace('/<li><a href="mylink.php">(.*)</a>/','placeholder',$str);
I highly recommend http://regex101.com/ for learning more about regex and how to make them work.
链接地址: http://www.djcxy.com/p/76726.html上一篇: 如何在MySQL中进行正则表达式替换?
下一篇: 替换替换锚文本