插件42:从URL地址读取标题

<?php // Plug-in 42: Get Title From URL

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$page   = "http://news.yahoo.com";
$result = PIPHP_GetTitleFromURL($page);

if (!$result) echo "The URL '$page' could not be accessed";
else echo "The title of '$page' is:<br /><br /><i>$result</i>";

function PIPHP_GetTitleFromURL($page)
{
   // Plug-in 42: Get Title From URL
   //
   // This plug-in takes the URL of a web page and returns that
   // page's title. If the page cannot be loaded then FALSE is
   // returned. The argument required is:
   //
   //    $page: The URL of a page, including the preceding
   //           http://

   $contents = @file_get_contents($page);
   if (!$contents) return FALSE;
   
   preg_match("/<title>(.*)<\/title>/i", $contents, $matches);
   return $matches[1];
}

?>

插件说明:

插件接受一个Werb页面的URL地址,读取并返回它的标题。他需要以下参数:

$page 字符串,包含需要检查的web页面的URL地址。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值