Finding the instance of a specific string and first 2 letters of next string and switch their places in php -


i have specific string is:

  <span style="color: green;"> 

i want function finds instance of string , further finds whether next string's first 2 characters

i have idea of searching character character, take long. there shorter solution it?

input:

  ab <span style="color: green;">  </strong> 

output:

  ab </strong> <span style="color: green;">   

the strong tag example, /b, /i, /li or other closing tag.

you can use preg_replace this, i.e.:

$myhtml = <<< lol ab <span style="color: green;">  </strong> lol;     $myhtml = preg_replace('%(<span style="color: green;">)(?:\s+)?(</.*?>)%i', '$2 $1', $myhtml);  echo $myhtml;  //ab </strong> <span style="color: green;"> 

it work tag comes after span.

demo:

http://sandbox.onlinephpfunctions.com/code/9dc934ece66856a92b041114140982dc822a6bec


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -