php中htmlspecialchars与htmlentiti用法
在php编程中,使用file_get_contents拿到网页之后,如果直接使用echo 输出,浏览器输出会自动解析,输出仍然为网页。
使用htmlspecialchars转换得到的content,然后获得所有的链接。截取。
截取时候会出现问题,
截取使用htmlspecialchars转换过的内容,截取方式:
function captureKeyArray($url)
{
$content=file_get_contents($url);
$pattern="/<a\s+href=.*<\/a>/imsU";
$match = array();
preg_match_all($pattern,$content,$match);
$matchFilter = array();
foreach($match[0] as $key=>$val)
{
$str= htmlspecialchars($val);
if(strpos($str,"img"))
{
}
else
{
//为什么不能直接过滤掉<,要使用<
$word = substr($str,strpos($str,'>',5)+4,strpos($str,"<",10)-strpos($str,'>',5)-4);
if($word!="")
{
array_push($matchFilter,$word);
}
}
}
return $matchFilter;
}
您可能感兴趣的文章:
php中htmlspecialchars与htmlentiti用法
php 去除html标记之strip_tags与htmlspecialchars的区别分析
php去除html标记strip_tags、htmlspecialchars区别
php表单提交特殊字符过滤方法
php实例:特殊字符处理函数的例子
php删除html标签的三种方法分享
php读取本地php文件源代码输出显示
php过滤非法字符函数
php如何做sql过滤
php 去除多余的HTML标签