Convert URL ending in .jpg .bmp .gif .png to <img>

Hi,

I’m learning PHP by writing a simple message board script. I have already a function defined to replace URLs with nchors, I just need to insert before this a function defined to replace URLs ending with image extensions to img tag (I’ll define later max width and height to not ruin the webpage). Preg_replace is one of the harder to learn (I think we’ll use this) and all I find on the web about images are bbcode parsers :C

Hi there,

Try:
[php]$newtext = preg_replace("/(http://)?[^\s]+.(jpg|png|gif|bmp)/i","<img src="$0" alt="" />",$text);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service