html parsing - Ignoring </span> tag and placing all closing tags before span opening tag in php -


my code in php is:

while(preg_match('%(<span style="color: green;">)(?:\s+)?(</.*?>)%i', $result2)==1){     $result2 = preg_replace('%(<span style="color: green;">)(?:\s+)?(</.*?>)%i', '$2 $1', $result2); } 

right have input such as:

 <span style="color: green;"></p></i>  

and code whenever tag closing after span green tag, placed before span. output above input be:

 </p></i><span style="color: green;"> 

i want if there span tag closing after span green tag, should ignored , other closing tags should placed first.. example input:

<span style="color: green;"></p></span></i>    

output:

 </p></i><span style="color: green;"></span> 

can me out in making change?

in general regex implementations can use look-ahead mechanism, (?!</span>)(</.*?>) instead of (</.*?>) in match/replace pattern.

otherwise, please check regex - how match except particular pattern solves general problem both standard , non-standard implementations.

you can rely bit less on regex, , check in loop if tag found matches , if break loop (if understand idea correctly).

edit: if want keep moving tags after span closed, can add accepted 'content', like: http://sandbox.onlinephpfunctions.com/code/8177a9afbdd5ac7c1660679d9cb362a9b48c29a4 accept more in span content, \w+ (your code loosing totally) , if want many span closing tags need make more generic too, idea behind same


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -