php str enhtml,php中htmlspecialchars和htmlentiti

Certain characters have special significance in HTML, and should

be represented by HTML entities if they are to preserve their meanings. This

function returns a string with some of these conversions made; the translations

made are those most useful for everyday web programming. If you require all HTML

character entities to be translated, use htmlentities()

instead.

Html entities:&lt &amp…

Html characters:  <>&

使用file_get_contents拿到网页之后,如果直接使用echo 输出,浏览器输出会自动解析,输出仍然为网页。

使用htmlspecialchars转换得到的content,然后获得所有的链接。截取。

截取时候会出现问题,

截取使用htmlspecialchars转换过的内容,截取方式如下:

$word =

substr($str,strpos($str,‘&gt‘,5)+4,strpos($str,"&lt",10)-strpos($str,‘&gt‘,5)-4);

function

captureKeyArray($url)

{

$content=file_get_contents($url);

$pattern="//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,‘&gt‘,5)+4,strpos($str,"&lt",10)-strpos($str,‘&gt‘,5)-4);

if($word!="")

{

array_push($matchFilter,$word);

}

}

}

return

$matchFilter;

}

原文:http://www.cnblogs.com/z497688734/p/3653530.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值