Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get string before last slash and after second last slash in URL [duplicate]

Tags:

regex

php

If I have a URL look like this:

http://wwww.example/test1/test2/test3/

How can I retrieve string test3 from the url above?

like image 549
Felix Avatar asked Dec 11 '22 08:12

Felix


1 Answers

$str = explode("/","http://wwww.example/test1/test2/test3/");
echo $str[count($str)-2];

DEMO: https://eval.in/83914

like image 156
Awlad Liton Avatar answered May 05 '23 00:05

Awlad Liton