regex help with getting tag content in PHP

后端 未结 4 1313
有刺的猬
有刺的猬 2021-01-28 03:47

so I have the code

function getTagContent($string, $tagname) {

    $pattern = \"/<$tagname.*?>(.*)<\\/$tagname>/\";
    preg_match($pattern, $string         


        
4条回答
  •  走了就别回头了
    2021-01-28 04:08

    Probably because the title is spread on multiple lines. You need to add the option s so that the dot will also match any line returns.

    $pattern = "/<$tagname.*?>(.*)<\/$tagname>/s";
    

提交回复
热议问题