开发者

getting parts of html file in php

开发者 https://www.devze.com 2023-01-31 06:52 出处:网络
i need to get two things out of an html file: text between <title> and </title开发者_运维百科>

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

精彩评论

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