general php-regex question

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
lordcoffee
Regular
Posts: 308
Joined: Tue Nov 29, 2005 10:22 pm
Location: Munich - Germany
Contact:

general php-regex question

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: general php-regex question

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
lordcoffee
Regular
Posts: 308
Joined: Tue Nov 29, 2005 10:22 pm
Location: Munich - Germany
Contact:

Re: general php-regex question

Post 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
Post Reply