Skip to main content
Participating Frequently
Jul 23, 2006 2:43 AM UTC
Question

PHP Regular Expressions

I am trying to write a script that searches for image tags and checks for alt tags within them. I am using preg_match_all to find all the img tags but i am messing up somewhere on my regular expression pattern.

I seriously just started learning these expressions days ago so i really do not know what i am doing here. For some reason my current expression: /<img.+\/>./ Doesnt find the next > after finding the first <img tag. It gets like the second or third one. Shouldnt it cut it off after it finds the first >?

In addition, my other expression (for extracgting the src tag doesnt stop after the second quatation. Insead it goes for a few more. /src=\".*\"/ is what i have now.

What do i need to fix so that the results i get back dont include anything after the first > or the second quation mark?
This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

Inspiring
Jul 23, 2006 9:16 AM UTC
barbedwire103 wrote:
> What do i need to fix so that the results i get back dont include anything
> after the first > or the second quation mark?

/<img[^>]+>/

/src\s?=\s?"[^"]+"/

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Translate