simplexml_load_string()函数应用

通过SimpleXML从网页中抽取出网页标题和描述,页面内容被传递给simplexml_load_string()函数后被解析成一个XML文档并返回一个容易处理的对象。如果系统中安装了libtidy扩展,可使用它来规范代码,否则就消除可能产生的警告信息:

$file = tidy_repair_string($file);
$html = simplexml_load_string($file);

// or: $html = @simplexml_load_string($file);

// extact the title
if ($html->head->title)
{
$title = $html->head->title;
}
else
{
// use the filename if a title is not found
$title = basename($row['DOCUMENT_URL']);
}

// extract the description
$description = ‘No description provided.’;
foreach($html->head->meta as $meta)
{
if (isset($meta['name']) && $meta['name'] == ‘description’)
{
$description = $meta['content'];
break;
}
}

转载于:https://www.cnblogs.com/lsok/archive/2012/01/30/2331761.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值