Forum Moderators: coopster

Message Too Old, No Replies

chomp

deleting the end of an url

         

turbohost

7:21 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Hi,

I want to remove the end of an URL (e.g. delete /bla/bibi/test.html in [example.com...] How can I do this in php?

Turbo

lazydog

8:24 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Here you go -

$arr =parse_url('http://www.example.com/bla/bibi/test.html');
$host = $arr['host'];

$host now holds literal "www.example.com"

Saurabh.

turbohost

8:29 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Thx, it works :->

coopster

8:30 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could add the scheme back in as well:
<?php 
$arr = parse_url [php.net]('http://www.example.com/bla/bibi/test.html');
$scheme = $arr['scheme'];
$host = $arr['host'];
print $scheme.'://'.$host; // "http://www.example.com"
?>