On Monday, February 18, 2002, at 03:44  PM, Mitch Tishaw wrote:

> I need a little help with the ereg_replace function.  I have the 
> following code:
>
> $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a 
> href=\"\\0
> \">\\0</a>", $text);
>
> which pads a url with an href tag to make it clickable.  Here's what I 
> would
> like to do:  In the case of the url ending with .gif or .jpg, I would 
> like to
> pad it with an img src tag instead, so it shows up as an actual 
> picture.  Does
> anyone know how I can modify the above code to do this?  Thanks in 
> advance.

This will not necessarily work every single time, nor will it ONLY work 
on images, but I tried -- maybe it can help you.  So why don't you test 
it out on maybe ten or so different image URLs.  If it works, go with 
it, but I accept no liability.  (Also, this regex has not been optimized 
for speed -- sorry, I don't have time to play with it.)

$text = "http://www.domain.com/directory/images/image.jpg";
preg_replace("(http://[^<>\s]+[-a-zA-Z0-9_/.]+\.(gif|jpg|jpeg)$)", "<img 
src=\"\1\" />", $text);

HTH


Erik



----

Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to