【问题标题】:getting parts of html file in php在php中获取部分html文件
【发布时间】:2010-12-15 19:13:03
【问题描述】:

我需要从 html 文件中得到两件事:

  1. <title></title> 之间的文本
  2. <body></body> 之间的文本

有人知道怎么做吗?这是我到目前为止所拥有的:

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

我需要在文本框中回显标题,在文本区域中回显正文。

【问题讨论】:

标签: php html html-parsing


【解决方案1】:

不要使用正则表达式来解析 HTML。见this answer。请改用DOMDocument::LoadHTML

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    相关资源
    最近更新 更多