Code前端首页关于Code前端联系我们

php获取当前网页标题,php获取一个网页的内容

terry 3年前 (2023-09-30) 阅读数 42 #PHP
文章标签 PHP Date()

本文目录一览:

  • 1、php怎么通过地址去获取一个网页的标题title里面的内容
  • 2、请问php如何截取指定页面的标题
  • 3、求一个简易的php爬虫提取网页的title

php怎么通过地址去获取一个网页的标题title里面的内容

用正则表达式技术可以实现,代码如下:

?php

$f=file_get_contents('

);

$regex='/title.*\/title/';

$a= array();

$b=preg_match($regex,$f,$a);

echo(trim($a[0],"title/title"));

?

请问php如何截取指定页面的标题

?php

$url = "";

$data = @file_get_contents($url);

preg_match("/title([\s\S]*?)\/title/i",$data, $matches);

echo $matches[1];

?

测试过可以的,只是注意baidu的标题不知道为啥多出很多个空格,如果不需要空格,可以

echo trim($matches[1]);

求一个简易的php爬虫提取网页的title

header("Content-Type: text/html; charset=gbk");

$url = "";

$fcontents = file_get_contents($url);

if (ereg("title(.*)/title", $fcontents, $regs)){echo "ok";}else{echo "error";}

echo "br";

print_r($regs);

版权声明

本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。

热门