Page 1 of 1

general php-regex question

Posted: Wed Mar 16, 2011 4:34 pm
by lordcoffee
Hey there! It's a long time ago since using s9y but I'm back :wink:

I have a problem with php here and need some help.
Just a small example:

What I have is:
<img src="foo" alt="bar" />

what I need is some php preg_replace or something like that what transforms the
img so that the result would be:

<div title="foo"></div>

Sound strange I know but I need a php solution.
I tried a lot of stuff but I'm not that good in php and less in regex.

Thanks for any help!
Greetings lordcoffee

Re: general php-regex question

Posted: Wed Mar 16, 2011 4:40 pm
by garvinhicking
Hi!

Code: Select all

<?php
$html = '<img src="foo" alt="bar" />';

echo preg_replace('@<img.*src="([^"]+)"[^>]+>@i', '<div title="\1"></div>', $html);
HTH,
Garvin

Re: general php-regex question

Posted: Wed Mar 16, 2011 4:59 pm
by lordcoffee
holy sh...

you don't want to know what I have tried :oops:
dind't know that it could be that easy 8)

THANKS IN ADVANCE, GARVIN!

greetings, lordcoffee