PHP获取网页源代码、网页标题的实现代码
时间:2021-07-01 10:21:17
帮助过:3人阅读
- $lines = file('http://bbs.it-home.org/');
- foreach ($lines as $line_num => $line) {
- echo "Line {$line_num} : " . htmlspecialchars($line) . "
\n"; - }
- ?>
2,获取网页的标题:
- $url = 'http://bbs.it-home.org';
- $lines_array = file($url);
- echo $lines_array;
- echo "
"; - $lines_string = implode('', $lines_array);
- eregi("(.*)", $lines_string, $head);
- echo "head:".$head;
- echo "
"; - print_r($head);
- echo "
"; - echo "title:".$head[1];
- ?>
|