PHP Url Stripping help needed

Associate
Joined
18 Oct 2002
Posts
747
I have a dynamic url that is called $name

The url is in the form of
Code:
http://www.mysite.co.uk/gallery/index.php?album=Seals

But it also changes its form depending on were it is called from and can be something like the one below

Code:
http://www.mysite.co.uk/images/index.php?album=Seals&page=2

Where the “&page=2” is added. The “2” can also be any number from 2 upwards.

Is there some PHP code that I can use to look at the $name variable and strip everything off the end of the url from and including the “&” if it is present, to leave me with a url that always takes the form of the first example?
 
Code:
<?php

$str = "http://www.mysite.co.uk/images/index.php?album=Seals&page=2";
$str = explode("&page=",$str);
$str = $str[0];

echo $str;

?>
Seems to do the job. Reg expressions would be useful if it needs to be more precise :)
 
Back
Top Bottom