Preg match text in php between html tags

前端 未结 3 590
抹茶落季
抹茶落季 2020-11-29 06:22

Hello I would like to use preg_match in PHP to parse the \"Desired text\" out of the following from a html document

Desired text &

3条回答
  •  一个人的身影
    2020-11-29 06:43

    if you want to return multiple matches then need to use preg_match_all(). You then loop through the second result group ($match[1]) to get just the content between tags.

    $source = "

    Desired text1

    ". "

    Desired text2

    ". "

    Desired text3

    "; preg_match_all("'

    (.*?)

    'si", $source, $match); foreach($match[1] as $val) { echo $val."
    "; } Outputs: Desired text1 Desired text2 Desired text3

提交回复
热议问题