如何在php中删除标签之间的文本?
尽管使用PHP多年,但我从未真正学会如何使用表达式来正确截断字符串......它现在正在后面咬我!
任何人都可以为我提供一些帮助来截断这一点吗?我需要从URL中切出文本部分,转动
<a href="link.html">text</a>
到
<a href="link.html"></a>
尽管使用PHP多年,但我从未真正学会如何使用表达式来正确截断字符串......它现在正在后面咬我!
任何人都可以为我提供一些帮助来截断这一点吗?我需要从URL中切出文本部分,转动
<a href="link.html">text</a>
到
<a href="link.html"></a>
$str = preg_replace('#(<a.*?>).*?(</a>)#', '$1$2', $str)
使用 SimpleHTMLDom:
<?php
// example of how to modify anchor innerText
include('simple_html_dom.php');
// get DOM from URL or file
$html = file_get_html('http://www.example.com/');
//set innerText to null for each anchor
foreach($html->find('a') as $e) {
$e->innerText = null;
}
// dump contents
echo $html;
?>