Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP正则表达式-从HTML标记中删除文本_Php_Regex - Fatal编程技术网

PHP正则表达式-从HTML标记中删除文本

PHP正则表达式-从HTML标记中删除文本,php,regex,Php,Regex,如何删除标记之间的所有文本 输入 <div> <p>testing</p> <div>my world</div> </div> 测试 我的世界 输出 <div> <p></p> <div></div> </div> 您可以使用或。 下面的示例使用后者,尽管您可能希望使用最适合自己的方法 include("si

如何删除标记之间的所有文本

输入

<div>
    <p>testing</p>
    <div>my world</div>
</div>

测试

我的世界
输出

<div>
    <p></p>
    <div></div>
</div>

您可以使用或。 下面的示例使用后者,尽管您可能希望使用最适合自己的方法

include("simple_html_dom.php");

$str = '
<div>
    <p>testing</p>
    <div>my world</div>
</div>
';

$html = str_get_html($str);
foreach($html->find("text") as $ht) {
   $ht->innertext = "";
}
$html->save();
echo $html;
include(“simple_html_dom.php”);
$str='1
测试

我的世界 '; $html=str\u get\u html($str); foreach($html->find(“文本”)作为$ht){ $ht->innertext=“”; } $html->save(); echo$html;
您可以使用两个捕获组,在替换时消除它们之间的字符:

(\<.+\>).*(\<\/.+\>)
(\).*(\)
工作示例: