getting parts of html file in php
i need to get two things out of an html file:
- text between
<title>
and</title开发者_运维百科>
- 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
.
精彩评论