how to remove a tag and its contents using regular expression?

前端 未结 5 2561
囚心锁ツ
囚心锁ツ 2021-02-20 06:09

$str = \'some text tag contents more text \';

My questions are: How to retrieve content tag contents which is between

5条回答
  •  一整个雨季
    2021-02-20 06:44

    If MY_TAG can not be nested, try this to get the matches:

    preg_match_all('/(.*?)<\/MY_TAG>/s', $str, $matches)
    

    And to remove them, use preg_replace instead.

提交回复
热议问题