很多站长朋友们都不太清楚php去掉所有标签,今天小编就来给大家整理php去掉所有标签,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php使用正则表达式去掉一段网页内容中所有标签,求助 2、 能用PHP 去掉所有html标签里的部分属性吗?只要保留标签里的超链接即可! 3、 php如何移除xml标签下所有的标签 php使用正则表达式去掉一段网页内容中所有标签,求助<?php
$string="<php>1<p>02</p><p>888</p></php><p>123</p><php><p>234</p></php>";
$pattern = '/<php>([\s\S]*)<\/php>/iU';
preg_match_all($pattern,$string,$d);
foreach ($d[1] as $val) {
$string = str_replace($val,strip_tags($val),$string);
}
echo $string;
?>
能用PHP 去掉所有html标签里的部分属性吗?只要保留标签里的超链接即可!<?php
$file='<div id="m"><p id="lg"><img src="/data/upload/help/202303/02/db50f755638da43e096b491d4e8e2c21.gif" width="27px" height="12px" usemap="#mp"><map name="mp"><a shape="rect" coords="40,25,230,95" href="yuanso/index.html" target="_blank" title="点此进入空间" ></map></p><p id="nv"><a href="yuanso/index1.html">文字1</a><b>文字2</b><a href="yuanso/index3.html">文字3</a></p></div>
';
$del=array("/name=.+?['|\"]/i","/src=.+?['|\"]/i","/id=.+?['|\"]/i","/width=.+?['|\"]/i","/height=.+?['|\"]/i","/usemap=.+?['|\"]/i","/shape=.+?['|\"]/i","/coords=.+?['|\"]/i","/target=.+?['|\"]/i","/title=.+?['|\"]/i");
$file = preg_replace($del,"",$file);//去除style样式
$file = str_replace(" ","",$file);//去除所有空格
$file = str_replace("<ahref=","<a href=",$file);//还原空格
echo $file;
?>
php如何移除xml标签下所有的标签<?
$str='<config>
<syncinfo username="admin">
<iconv>
<item name="xxx" index="xx" />
<item name="xxx" index="xx" />
<item name="xxx" index="xx" />
</iconv>
</syncinfo>
</config>';
$name='iconv';
$tag1="<$name>";
$tag2="</$name>";
$p1=strpos($str,$tag1);
$p2=strpos($str,$tag2);
$str1=substr($str,$p1+strlen($tag1),$p2-$p1-strlen($tag1));
echo str_replace($str1,"",$str);
?>
关于php去掉所有标签的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php去掉所有标签 php去掉标签中的属性的详细内容...