I want to read string from right to left. For example I want to get 50940775 from $game in below code.
I referred another stackoverflow question. They said to use $, but it is not working for me. I use below code.
$game = 'http://www.myspace.com/sdsf/1223232/videos/video/50940775black';
preg_match('/\/(.*?)black$/', $game, $match);
print_r($match[1]);
Note : $game Url are different like below
http://www.myspace.com/sdsf/1223232/black/video/50940775black
http://www.myspace.com/sdsf/1223232/videos/12345/50940775black
http://www.myspace.com/sdsf/1223232/videos/games129kj/5675999black
Since you want to get numbers, you can specify that you only want them (
[0-9]+) instead of every thing (.*). With.*it will retrieve every thing between the first/found andblack. So, in your case:/www.myspace.com/sdsf/1223232/videos/video/50940775blackTry this one:
Live demo.
Edit:
In fact, it’s hard to read from right to left. What you can do is explode the url by
/and then use the last part to apply your regex: