Reputation: 55
I have a really simple question that I couldn't solve using online help...
Well I have an URL, eg. "www.google.com/hello/xxxxxxxx"
What I'm trying to do is get that xxxxxxx and print it. I have already gathered the URL of the page I want to split with a SQL statement, and it is now stored in the $row['url']. I have tried to get it it split when it reaches an "/"
This is my code right now:
$url = preg_split("[/.-]", $row['url']);
print_r($url);
But it doesn't work? Right now it doesn't even print anything... and I don't know what else to try!
Upvotes: 1
Views: 725
Reputation: 53198
How about using end()
with explode()
:
echo end(explode('/', $row['url']));
Output is: xxxxxxxx
.
Upvotes: 1
Reputation: 44844
Is this what you are looking for ?
$url = "www.google.com/hello/xxxxxxxx" ;
echo substr( strrchr( $url, '/' ), 1 );
Output: xxxxxxxx
Upvotes: 1