hey guys im haveing a problem with this function preg_match_all() im useing this pattern "/(<img)\s (src=\"( [a-zA-Z0-9\.;:\/\?&=_|\r|\n] (.*) \.(jpg|png) )\")/isxmU" to get all images links with jpg and png extinction but it will only get the img tag on this way <img src='link' .../> but if the <img> tag has an height or width it wont get it like that <img height='50px' width='50px' src='link' /> and i guess this problem cuz of my pattern im telling it to get only the src which is after the img tag directly but that not what i want i want to get the src of the img where ever the src were thanks for anyhelp
the code: $str = 'fdjsadfgjlk s<img src="http://fdgdfgsd.com/fsdfg.gif" width="40"/> fas da sdf <img width="40" height=30 src="http://fdgdfgsd.com/fsdfg.png" /> f<img width="40" height=30 src="http://fdgdfgsd.com/fsdfg.xxx" /> s<img/>'; $matches = array(); preg_match_all("/<img[\s\S]*?(.jpg|.png|.gif)+?[\s\S]*?>/im",$str,$matches); var_dump($matches); PHP: gives this: array(2) { [0]=> array(2) { [0]=> string(53) "<img src="http://fdgdfgsd.com/fsdfg.gif" width="40"/>" [1]=> string(64) "<img width="40" height=30 src="http://fdgdfgsd.com/fsdfg.png" /> " } [1]=> array(2) { [0]=> string(4) ".gif" [1]=> string(4) ".png" } } PHP:
well i guess the result is a little bit complicated, i mean my code only getting the img url here is my code preg_match_all("/(<img)\s (src=\"( [a-zA-Z0-9\.;:\/\?&=_|\r|\n] (.*) \.(jpg|png) )\")/isxmU", file_get_contents("http://www.deviantart.com"), $images); $limit = 3; $i=0; foreach($images[3] as $image_url): $valid_files = substr($image_url, -3); $i++; if($i == $limit) break; echo $image_url."<br />"; endforeach; PHP: you can try it, it will give you two url's back cuz of the limit so it will only get the url of the img like that <img src='urlofimage.jpg' /> but if the img tag like this it will get nothing <img height='50px' width='100px' src='link.jpg' /> it dosn't have to be hight and width it can be anything else like alt or title, things like that so i want my pattern to get the src where ever the src were thank you
if you confuse using RegExp you can try this site to generate : http://txt2re.com/ its support Perl,PHP,Python,Java,Javascript,ColdFusion,C,C++, Ruby, VB, VBScript , J#.net, C#.net, C++.net, VB.net