开发者

getting parts of html file in php

i need to get two things out of an html file:

  1. text between <title> and </title开发者_运维百科>
  2. text between <body> and </body>

does anybody know how to do this? this is what i have so far:

$contents = file_get_contents($_GET['file']);
$title = preg_replace("/.*<title[^>]*>|<\/title>.*/si", "", $file);
$body = preg_replace("/.*<body[^>]*>|<\/body>.*/si", "", $file);

i need to echo the title in a textbox and the body in a textarea.


Do not use regex to parse HTML. See this answer. Instead, use DOMDocument::LoadHTML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜