$url = 'http://stackoverflow.com/questions?sort=newest';
// preg_quote escapes the dot, question mark and equals sign in the URL (by
// default) as well as all the forward slashes (because we pass '/' as the
// $delimiter argument).
$escapedUrl = preg_quote($url, '/');
// We enclose our regex in '/' characters here - the same delimiter we passed
// to preg_quote
$regex = '/\s' . $escapedUrl . '\s/';
// $regex is now: /\shttp\:\/\/stackoverflow\.com\/questions\?sort\=newest\s/
$haystack = "Bla bla http://stackoverflow.com/questions?sort=newest bla bla";
preg_match($regex, $haystack, $matches);
var_dump($matches);
// array(1) {
// [0]=>
// string(48) " http://stackoverflow.com/questions?sort=newest "
// }