Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: PHP Warning: parse_url

I pasted the code with an error in it. Use this function instead:

function bb_get_path( $level = 1, $base = false, $request = false ) {

if ( !$request )

$request = $_SERVER;

if ( is_string($request) )

{

// parse_url throws a warning for a url that has http:// as a query parameter and doesn’t start with http://

$pos = strpos($request, “http://”);

// Check if we found http:// in the string and it’s not at the beginning, and the url starts with a forward slash

if ($pos !== false && $pos > 0 && substr($request,0,1) == “/”)

{

// We got here, so it’s not at the beginning and is in the url. Add in the domain to the beginning

$oldRequest = $request; // Use a new variable since some PHP versions don’t like re-assigning

$request = “http://”.$_SERVER[“HTTP_HOST”].$oldRequest;

}

$request = parse_url($request);

}

if ( !is_array($request) || !isset($request) )

return ”;

$path = rtrim($request, ” tnrx0B/”);

if ( !$base )

$base = rtrim(bb_get_option(‘path’), ” tnrx0B/”);

$path = preg_replace(‘|’ . preg_quote($base, ‘|’) . ‘/?|’,”,$path,1);

if ( !$path )

return ”;

if ( strpos($path, ‘/’) === false )

return ”;

$url = explode(‘/’,$path);

if ( !isset($url[$level]) )

return ”;

return urldecode($url[$level]);

}

Skip to toolbar