日期:2014-05-17  浏览次数:20395 次

php如何通过地址去获取一个网页的标题title里面的内容。
比如,我在文本框里面输入一个网址。点击“获取标题”按钮,如何才能获取到标题并写入到下面的文本框里面。

------解决方案--------------------
一个后端页面 gettitle.php (代码我复制的,没测试)


function get_title($html)
{
  $html=strtolower($html);
$title = str_replace(" - ",",",cut($html,"<title>", "</title>" ));
//if ($title == "") $title = "无标题";
if ($title) $title=replace_word(textcut($title,80));
if ($title) $title=preg_replace("/<(.*?)>/","",$title);
return addslashes(trim($title));
}


你的前端页面 点击获取标题后 触发 ajax 到后端页面 取得返回的json 或字符串 赋值给你的相应input value