Convert Relative Links to Absolute Links with PHP Regex

Here is a quick post on how to find and replace relative links with absolute links using PHP Regular Expressions (regex).

$url = "http://myabsoluteurl.com/";
$ret = preg_replace('/((?:href|src) *= *[\'"](?!(http|ftp)))/i', "$1$url", $ret);