2010-12-15 130 views
1

我需要得到兩件事情出一個HTML文件:和</title><body></body>之間 越來越部分

  1. 文本之間<title>
  2. 文本沒有任何人知道這個怎麼做?這是我到目前爲止有:

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

    我需要回響在一個文本在文本框中的標題和正文。

+0

*(相關)* [解析HTML的最佳方法](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html/3577662#3577662) – Gordon 2010-12-15 20:15:02

+0

閱讀[解析Html The Cthulhu Way ](http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html) – AlexV 2010-12-15 20:33:25

回答