PHP – Add link to a URL in a string

function processString($s) {
    return preg_replace('/https?:\/\/[\w\-\.!~#?&=+\*\'"(),\/]+/','<a href="https://stackoverflow.com/questions/4217406/"$0"">$0</a>',$s);
}

Leave a Comment