I need a php regular expression that replaces one tag with another

后端 未结 4 1210
广开言路
广开言路 2021-01-24 08:23

Here is what I need to be able to do:

I need to match the following tag:

text sample
         


        
4条回答
  •  别那么骄傲
    2021-01-24 08:34

    You'll need several lines like this:

    preg_replace('|(.+?)|', '$1', $text);
    preg_replace('|(.+?)|', '$1', $text);
    preg_replace('|(.+?)|', '$1', $text);
    

    etc. Although if there's any possibility that the tags won't exactly match those regular expressions (which is usually the case, except for very simple machine-generated HTML), doing this with regular expressions becomes fiendishly complicated, and you'd be better off using a parser of some kind.

提交回复
热议问题