This will do it. Short explanations on how it works can be found in the codes comments:
<?php
# fixed syntax error string
$string = "lorem ipsum http://google.com dolor sit amet <img src=\"http://img.com/img.png\" />";
function make_clickable($text) {
    # explode string on spaces to array
    $arr = explode(' ', $text);
    # test each array element if it contains nothing else but a website
    foreach($arr as $key => $value){
        if(preg_match('#((^https?|ftp)://(\S*?\.\S*?))([\s)\[\]{},;"\':<]|\.\s|$)#i', $value)){
            # replace plain text urls with href links in array
            $arr[$key] = "<p><a href="". $value ."" class="link">". $value ."</a></p>";
        }
    }
    # rebuild array back to string
    $text = implode(' ', $arr);
    # return result
    return $text;
}
echo make_clickable($string);
?>
2
solved Find link URL in string not image