View Full Version : regular expression

04-30-2009, 10:02 AM
Hi all, sorry for so many posts.

Any who,

$line = fgets($fpointer);

$attribute = array('class="', 'id="', 'name="', 'alt="', 'content="', 'width="', 'height="', 'href="', 'type="', 'src="', 'media="');
foreach($attribute as $a)
$moo = preg_quote($a, "/");
$tag = preg_match_all("/$a([^-]+)\"/", $line, $matches);
foreach($matches[0] as $a)
echo "Line: ".$line_num." stuff: ".$a."<br />\n";


this is the code, it reads each line of a doc, and each line has a html tag on it. i want to gather the attributes.

$tag = preg_match_all("/$a([^-]+)\"/", $line, $matches);

gets the whole lot name="sdf" href="dfd" alt="sdfdf"

how do i stop " from being alowd in ([^-]+) that bit?

04-30-2009, 10:15 AM

Means find anything except a hyphen that is one or more so to add " inside to make (you've got escape the " though with a backslash)


and then put that into your new code.

Although the code you're using looks very inefficient, could you tell me what it does maybe I can make a better one.