|
|
|
||||
|
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() |
|
|||||||
| Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
|
Thread Tools |
|
|
#1 |
|
Confirmed User
Join Date: Nov 2004
Location: scv
Posts: 2,299
|
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? |
|
|
|
|
|
#2 |
|
Confirmed User
Join Date: Jul 2004
Location: Denmark ICQ: 7880009
Posts: 2,203
|
I'm thinking something similar to this:
Code:
preg_match_all("|src\=\"?'?`?([[:alnum:]:?=&@/._+-]+)\"?'?`?|i", $string, $matches);
|
|
|
|
|
|
#3 | |
|
Confirmed User
Join Date: Nov 2004
Location: scv
Posts: 2,299
|
Quote:
That works great. Thank you! |
|
|
|
|
|
|
#4 |
|
MFBA
Industry Role:
Join Date: Mar 2003
Location: PNW
Posts: 7,230
|
there are things other then images that use src= so you might want to be more explicit with that regex
|
|
|
|
|
|
#5 | |
|
Confirmed User
Join Date: Nov 2004
Location: scv
Posts: 2,299
|
Quote:
Good point. It matches anything after src even if it's not in an img tag. Any ideas? |
|
|
|
|
|
|
#6 |
|
MFBA
Industry Role:
Join Date: Mar 2003
Location: PNW
Posts: 7,230
|
Code:
preg_match_all("|src\=\"?'?`?([[:alnum:]:?=&@/._+-]+)+\.(gif|GIF|jpg|JPG)\"?'?`?|i", $string, $matches);
|
|
|
|
|
|
#7 |
|
Confirmed User
Join Date: Nov 2004
Location: scv
Posts: 2,299
|
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. |
|
|
|
|
|
#8 | |
|
Confirmed User
Join Date: Apr 2003
Location: Loveland, CO
Posts: 5,526
|
Quote:
__________________
Your post count means nothing. |
|
|
|
|
|
|
#9 | |
|
Confirmed User
Join Date: Nov 2004
Location: scv
Posts: 2,299
|
Quote:
|
|
|
|
|