first content here <...">

PHP regex - find and replace

I try to execute this regex and replace, but fail to do so.

Example

<SPAN class="one">first content here</SPAN> <SPAN class="two">second content here </SPAN> <SPAN class="three">one; two; three; and more.</span> <SPAN class="four">more content here.</span> 

I want to find every set of span tags and replace with something like this

To find

<SPAN class="one">first content here</SPAN>

Change to

<one>first content here</one>

just like the rest of the span tags.

class="one" , class="two" , etc. are the only key identifier that I use in a regular expression match expression. Therefore, if I find a span tag with this class, then I want to make a replacement. My main problem is that I cannot find the appearance of the first closing tag, so that it does it from beginning to end, which is useless. While I'm trying to do this with notepad ++, but have found that it has its limitations, so any php help would be appreciated.

considers

+4
source share
1 answer
 preg_replace('/<span class="(.*?)">(.*?)<\/span>/i', '<$1>$2</$1>', $input); 
+12
source

Source: https://habr.com/ru/post/1306266/


All Articles