note 12480 deleted from function.parse-url by jimw

From: Date: Fri, 21 Dec 2001 00:40:01 +0000
Subject: note 12480 deleted from function.parse-url by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23660@lists.php.net to get a copy of this message
recently i needed a way to get the actual url and path with a trailing slash, not the path and file. i did this by going. $urlarr = parse_url($url); if ($urlarr[path] != ""){ $foo = substr($urlarr[path], 0, strrpos($urlarr[path], "/") + 1); } else { $foo = "/"; } $foo = "$urlarr[scheme]://$urlarr[host]$foo"; #if u just want the path not the scheme and host just erase the line above #if $url was "http://www.pricezapper.com" $foo would end up as "http://www.pricezapper.com" #if $url was "http://www.pricezapper.com/" $foo would end up as "http://www.pricezapper.com" #if $url was "http://www.pricezapper.com/somedir/" $foo would end up as "http://www.pricezapper.com/somedir/" #if $url was "http://www.pricezapper.com/somedir/somefile.php" $foo would end up as "http://www.pricezapper.com/somedir/" might not be the cleanest way to do it, but it works. note this is probably not very useful for your own site, but i was parsing url's that were input.

« previous php.notes (#23660) next »