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

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

    For the basic example that you've given.

    text sample';
    $pattern = '/(.+?)<\/SPAN>/';
    $replacement = '$1'
    echo preg_replace($pattern,$replacement,$string);
    ?>
    

    will do the trick. The pattern regex is quite easy - it's exactly what you're looking for (with quotes and '/' escaped) with a (.+?) which says to include all possible characters until the close of the SPAN tag. This assumes that you're code is consistently formatted, you could append a 'i' to the end of $pattern to make it case-insensitive.

    Note that this isn't really the right way of doing it.

提交回复
热议问题