Solutionabc
asked on
PHP get part of string
Hi I have a string that I would like to extract the user name from. The string looks like the following:
http://gdata.youtube.com/feeds/api/users/kidrauhl
The string will always have a different user name attached to it like:
http://gdata.youtube.com/feeds/api/users/testUser
How can I always be sure to grab the user name?
thanks!
http://gdata.youtube.com/feeds/api/users/kidrauhl
The string will always have a different user name attached to it like:
http://gdata.youtube.com/feeds/api/users/testUser
How can I always be sure to grab the user name?
thanks!
If the user name is always at the end, you can use explode('/', $string) and take the end() of the resulting array.
$str = "http://gdata.youtube.com/feeds/api/users/kidrauhl";
$result = preg_match("/(http\:\/\/gdata\.youtube\.com\/feeds\/api\/users\/)(.*)$/",$str,$matches);
print_r($matches);
#or
$result = preg_match("/.*\/(.*)$/",$str,$matches);
print_r($matches);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry - I meant to post a link to the code snippet I posted above.
http://www.laprbass.com/RAY_temp_solutionABC.php
HTH, ~Ray
http://www.laprbass.com/RAY_temp_solutionABC.php
HTH, ~Ray