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

后端 未结 4 1215
广开言路
广开言路 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:39

    Regular expressions are not designed for tag manipulation.

    If you have any form of nesting going on, it gets messy.

    However, given the very simple example provided you could perhaps do this:

    $MyString = preg_replace
        ( '/(?si)(.*?)<\/SPAN>/'
        , '$1'
        , $MyString
        );
    


    But this is flawed in many ways, and you are much better off using a tool designed for manipulating tags instead.

    Have a look at DOMDocument->loadHTML() and related functions.

提交回复
热议问题