3

タイトルタグのコンテンツを除外するこの正規表現の何が問題になっていますか?

$plaintext = preg_match('#<title>(.*?)</title>#', $html);

$html には、ページ全体の html コードがあります。

4

3 に答える 3

5

有効な答えが得られなかったようです。タイトルタグを削除しましょう。

探す:(?s)<title>.*?</title>

交換:""

コード:

$regex = "~(?s)<title>.*?</title>~";
$ replaced = preg_replace($regex,"",$pagecontent);

正規表現の説明

(?s)                     # set flags for this block (with . matching
                         # \n) (case-sensitive) (with ^ and $
                         # matching normally) (matching whitespace
                         # and # normally)
<title>                  # '<title>'
.*?                      # any character (0 or more times (matching
                         # the least amount possible))
</title>                 # '</title>'
于 2014-06-03T01:40:16.380 に答える