How to remove the string from starting after certain character

Viewed 49

I have a string: /userPosts/hemlata993/20 I want to remove this /userPosts/hemlata993/.

I checked some answers but not being able to remove the first part. How can I do that? I am using php.

$string = /userPosts/hemlata993/20

I want the output as 20 because 20 is the directory or file name that I want to get

2 Answers

You can do it as follows:

$p =  basename(parse_url("/userPosts/hemlata993/20")['path']);
echo $p; //20

If this is what you want and the format of the string is always going to be like the one that you provided, this will work:

$string = "/userPosts/hemlata993/20";
$string_arr = (explode("/",$string));
echo $string_arr[3];
Related