Remove Anything After The Forward Slash
Moderator: General Moderators
Remove Anything After The Forward Slash
Hi,
How would I remove any text after the forward slash in a string..
Lets say I have
$strdata = "google.com/adsense";
How would I remove the "/" and "adsense".
But I want to make sure I can remove absolutley anything after the forward slash (not just adsense)
How would I go about this?
How would I remove any text after the forward slash in a string..
Lets say I have
$strdata = "google.com/adsense";
How would I remove the "/" and "adsense".
But I want to make sure I can remove absolutley anything after the forward slash (not just adsense)
How would I go about this?
Im not sure, but you could use $_SERVER['HTTP_HOST']; to get "www.google.com" straight away.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
If you're not comfortable with regex you could use parse_url()
There are plenty of pre-written URL/URI regex patterns available through search if you want to go that route.
There are plenty of pre-written URL/URI regex patterns available through search if you want to go that route.
There may be but as I said, I cant understand it.
I tried the code in the first reply to the function:
and all I get is:
I tried the code in the first reply to the function:
Code: Select all
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>and all I get is:
Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor )
Warning: parse_url() expects exactly 1 parameter, 2 given in /******/test.php on line 6