I have the following script that adds hyperlink tags to URL's found in a string of plain text. I want it to continue that function, but ALSO to add img tags to URL's pointing to image files. In other words, http://www.thesetwo.com/test.jpg will be converted to <img src="http://www.thesetwo.com/test.jpg">http://www.thesetwo.com/test.jpg</a> AND I still want it to link other URL's such as http://www.thesetwo.com to <a href="http://www.thesetwo.com">http://www.thesetwo.com</a>.
Got any ideas? I would appreciate any help.
<?
$text = "This is the first line of a long text. Be sure to see http://www.thesetwo.com/test.jpg and check out www.thisorthat.com and also http://www.thesetwo.com and even http://this.orthat.com/index.php.";
$text= preg_replace("/(?<!quot;|[=\"]|:\/\/)\b((\w+:\/\/|www\.).+?)"."(?=\W*([<>\s]|$))/i", "<a href=\"$1\" target=\"_blank\">$1</a>", $text);
$text= preg_replace("/href=\"www/i", "href=\"http://www", $text);
echo $text;
?>