$loc = preg_replace("/(.*?)Location: (.*?)\n(.*)/s", '$2', preg_replace("[\r]", '', $test));

Rensar allt framför och bakom exempelvis följande text:

Server: Apache
X-Powered-By: PHP/5.3.1
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Location: http://www.tornevall.net/index.php?id=77
Content-Type: text/html

Utresultatet blir:

http://www.tornevall.net/index.php?id=77