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
Post a Comment