mike42 Posted September 11, 2008 Share Posted September 11, 2008 hi i will to grab this image tags and download from source url match string: <div id="divnewsh"><img src="/news/image/imagename.jpeg" alt="blabla" width="300" border="0" class="imgnews"/></div> how can i only image name and ext. (imagename.jpeg) matching if (preg_match('#<div id="divnewsh"><img src="(.*?)"#', $f, $matches)) { $images=$matches[1]; $images=trim($images); $url = "http://urldomain.com".$images; $target = "./news/".$images; $file = fopen($target,"r"); while(!feof ($file)) { $content1 = fgets($file, 4096); $content .=$content1; } fclose($file); $file = fopen($target,"w"); fwrite($file,$target); fclose($file); } thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/123705-solved-img-name-and-ext-grabbing/ Share on other sites More sharing options...
nrg_alpha Posted September 11, 2008 Share Posted September 11, 2008 Here's what I came up with... $str = '<div id="divnewsh"><img src="/news/image/imagename.jpeg" alt="blabla" width="300" border="0" class="imgnews"/></div>'; preg_match('#([^/]+\.(?:jpeg|jpg|gif))#i', $str, $match); echo $match[1]; Ouput: imagename.jpeg From an efficiency perspective, I have a feeling it can be faster... but for this single string check, it seems to do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/123705-solved-img-name-and-ext-grabbing/#findComment-638770 Share on other sites More sharing options...
nrg_alpha Posted September 11, 2008 Share Posted September 11, 2008 Come to think of it, I suppose you can use this slightly modified pattern as well... preg_match('#([^/]+\.(?:jpe?g|gif))#i', $str, $match); Quote Link to comment https://forums.phpfreaks.com/topic/123705-solved-img-name-and-ext-grabbing/#findComment-638774 Share on other sites More sharing options...
mike42 Posted September 11, 2008 Author Share Posted September 11, 2008 Come to think of it, I suppose you can use this slightly modified pattern as well... preg_match('#([^/]+\.(?:jpe?g|gif))#i', $str, $match); thanx nrg_alpha works great Quote Link to comment https://forums.phpfreaks.com/topic/123705-solved-img-name-and-ext-grabbing/#findComment-638894 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.