![]() |
Question for php and regex gurus...
I need to parse html for any image tags and store all of them in an array...
So if this is the html: blah blah <img src="asdf.jpg" width="150"> more blah <img border="1" src="kasdf.gif"> The array should be: $images[0] = asdf.jpg $images[1] =kasdf.gif Anybody know how I can do this? |
I'm thinking something similar to this:
Code:
preg_match_all("|src\=\"?'?`?([[:alnum:]:?=&@/._+-]+)\"?'?`?|i", $string, $matches); |
Quote:
That works great. Thank you! |
there are things other then images that use src= so you might want to be more explicit with that regex
|
Quote:
Good point. It matches anything after src even if it's not in an img tag. Any ideas? |
Code:
preg_match_all("|src\=\"?'?`?([[:alnum:]:?=&@/._+-]+)+\.(gif|GIF|jpg|JPG)\"?'?`?|i", $string, $matches); |
Thanks for the help. What can I use to match just the image name from the string extracted from the first match?
Ie. How do I match just pic.jpg out of: src="http://example.com/images/pic.jpg" I tried: preg_match("/\/.+?\.jpg/", $matches[1], $imagematch); but that matches the longest string possible (//example.com/images/pic.jpg) Thanks. |
Quote:
|
Quote:
|
| All times are GMT -7. The time now is 01:12 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123