Regular Expression Help
-
Hi, I’m working on a plugin which searches the content of a post for a href links and adds a style to it based on if it’s an external link or if it’s an image file.
I’ve got the following already:
return preg_replace(
array(
'/(?(?=<a>]*>.+</a>)
(?:</a><a>]*>.+</a>)
|
([^="']?)((?:https?|ftp|bf2|)://[^<> nr]+)
)/iex',
'/</a><a>]*)target="?[^"']+"?/i',
'/</a><a>]+)>/i',
'/(^|s)(www.[^<> nr]+)/iex',
'/(([_A-Za-z0-9-]+)(.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)
(.[A-Za-z0-9-]+)*)/iex'
),
array(
"stripslashes((strlen('2')>0?'1</a><a>2</a>3':''))",
'<a1',
'<a rel="lightbox">',
"stripslashes((strlen('2')>0?'1</a><a>2</a>3':''))",
"stripslashes((strlen('2')>0?'<a></a>':''))"
),
$text
);
I have two problems with this.
1) I’m not sure how to determine the difference between a link and a link to an image file. I’d like to apply different styles to each2) When I have an img src like this:
<img src="http://www.aidslifecycle.org/images/alc5_logo.gif"/>
It replaces it with this:
<img src="<a href="http://www.aidslifecycle.org/images/alc5_logo.gif"/" rel="lightbox" class="ext" >http://www.aidslifecycle.org/images/alc5_logo.gif"/</a>>Can anyone help me out? I’m not very good with Regular expressions!
The topic ‘Regular Expression Help’ is closed to new replies.