djtozz Posted September 30, 2009 Share Posted September 30, 2009 lets say I want I want to grab the filename (last part) from following url format: mysite.com/dl/10587125/09c6247/filename.html then i was hoping following code should do it: preg_match("/mysite\.com\/dl\/\d+\/w+\/(.+)/",$words,$match); But this gives me a blank result insteed of 'filename.html" Am I missing something? Quote Link to comment https://forums.phpfreaks.com/topic/176085-solved-a-little-help-using-preg-match/ Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 Do you have to use regex? $path = "mysite.com/dl/10587125/09c6247/filename.html" $filename = basename($path); Quote Link to comment https://forums.phpfreaks.com/topic/176085-solved-a-little-help-using-preg-match/#findComment-927842 Share on other sites More sharing options...
djtozz Posted September 30, 2009 Author Share Posted September 30, 2009 Do you have to use regex? $path = "mysite.com/dl/10587125/09c6247/filename.html" $filename = basename($path); Thanks for your help, it is actually part of a code to calculate "$caption" The first part of the code works like a charm (type==1 rapidshare) The second part (type==2 hotfile) gives me a a empty record, not sure what's wrong.. $caption=''; if($type==1) { $words=$links[$j]; preg_match("/rapidshare\.com\/files\/\d+\/(.+)/",$words,$match); unset($words); $words=$match[1]; unset($match); $words=preg_split("/[_\.\-]/",$words); $lastword=array_pop($words); if($lastword=="html") array_pop($words); $words=implode(" ",$words); $words=preg_replace("/\s{2,}/"," ",$words); $caption=mysql_real_escape_string($words); unset($words); } if($type==2) { $words=$links[$j]; preg_match("/hotfile\.com\/dl\/\d+\/w+\/(.+)/",$words,$match); unset($words); $words=$match[2]; unset($match); $words=preg_split("/[_\.\-]/",$words); $lastword=array_pop($words); if($lastword=="html") array_pop($words); $words=implode(" ",$words); $words=preg_replace("/\s{2,}/"," ",$words); $caption=mysql_real_escape_string($words); unset($words); } Quote Link to comment https://forums.phpfreaks.com/topic/176085-solved-a-little-help-using-preg-match/#findComment-927860 Share on other sites More sharing options...
RussellReal Posted September 30, 2009 Share Posted September 30, 2009 preg_match("/.*\/(.*)$/i",$path,$m); Quote Link to comment https://forums.phpfreaks.com/topic/176085-solved-a-little-help-using-preg-match/#findComment-927866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.