Regular expression

Hi.
I need to replace, in all <img ... /> tags of HTML code with the following data:

' align="right" '      with     ' align="right" style="border:1px" '
' align="left" '      with     ' align="right" style="border:12px" '

Any help or clue to build a Regular expression?

Tank you for reading and for help.
valverde2006Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard QuadlingSenior Software DeveloperCommented:
<?php
$s_old_html = <<< END_HTML
<img src="">
<img align="left" src="">
<img src="" align="left">
<img align="right" src="">
<img src="" align="right">

END_HTML;

// Make sure you do the right=>right first as left=>right=>right otherwise
$as_search = array
      (
      '`(<img.*?)align="right"(.*?>)`sim',
      '`(<img.*?)align="left"(.*?>)`sim',
      );
      
$as_replace = array
      (
      '\1align="right" style="border:12px"\2',
      '\1align="right" style="border:1px"\2',
      );

$s_new_html = preg_replace($as_search, $as_replace, $s_old_html);

echo "Old HTML\n$s_old_html\n\nNew HTML\n$s_new_html\n\n";
?>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard QuadlingSenior Software DeveloperCommented:
The above code outputs ...

Old HTML
<img src="">
<img align="left" src="">
<img src="" align="left">
<img align="right" src="">
<img src="" align="right">


New HTML
<img src="">
<img align="right" style="border:1px" src="">
<img src="" align="right" style="border:1px">
<img align="right" style="border:12px" src="">
<img src="" align="right" style="border:12px">
0
Richard QuadlingSenior Software DeveloperCommented:
Thanks for the points.

If you need any more help, always come back.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.