What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Preg replace syntax

Preg replace syntax
Author: Message:
bramvandeperre
Junior Member
**

Avatar
Some random dude

Posts: 56
Reputation: 3
32 / Male / Flag
Joined: Oct 2007
Status: Away
O.P. Preg replace syntax
Heya all!

I got some little question for you.
code:
<img src="image.png" alt="blah" /> this is an image.


should become
code:
<a href="image.png">blah</a> this is an image.


I wanted to do this using a preg replace, but I suck in writing patterns.

Can anyone help? make sure that images are changed into hyperlinks... if there's no alt, the filename should be the text (so not only preg_replace but also some if/else thingies :P

thanks in advance

Bram

oh almost forgot: it's PHP...

This post was edited on 12-05-2008 at 11:17 PM by bramvandeperre.
12-05-2008 10:54 PM
Profile E-Mail PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: Preg replace syntax
Little regex without the alt thingy you wanted, i'm sure you or someone else can make that work for you

Regex:
code:
<img src=\"(.*)"\salt=\"(.*)" />(.*)
Replacement string:
code:
<a href=\"\1\">\2</a>\3
[Image: 1-0.png]
             
12-05-2008 11:31 PM
Profile PM Web Find Quote Report
bramvandeperre
Junior Member
**

Avatar
Some random dude

Posts: 56
Reputation: 3
32 / Male / Flag
Joined: Oct 2007
Status: Away
O.P. RE: RE: Preg replace syntax
quote:
Originally posted by Ezra
Little regex without the alt thingy you wanted, i'm sure you or someone else can make that work for you

Regex:
code:
<img src=\"(.*)"\salt=\"(.*)" />(.*)
Replacement string:
code:
<a href=\"\1\">\2</a>\3


thanks alot, but what if there is no alt at all? then the filename should be there (like image001.jpg or so)
12-05-2008 11:40 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On