From: [EMAIL PROTECTED]
Operating system: Win2K
PHP version: 4.0.6
PHP Bug Type: Output Control
Bug description: break doesn't stop foreach from iterating over array
I'm running the following function in conjunction with the DOM XML stuff to
create a SAX parser. Trouble is that the following code doesn't seem to
stop iterating over the $startTags array when it hits the break command.
function startElement ($parser, $name, $attrs)
{
global $startTags, $xmlPath, $htmlContent, $monthWords;
$xmlPath .= "/$name";
foreach ($startTags as $tag => $value)
{
if (substr($xmlPath, strlen($xmlPath) - strlen($tag), strlen($tag)) ==
$tag)
{
$htmlContent .= $startTags[$tag];
if ($name == "url")
{
if (isset ($attrs["target"]))
{
$htmlContent .= " target=\"$attrs[target]\"";
}
$htmlContent .= " href=\"$attrs[page]\">";
break; // Stop iterating through tags
}
else if ($tag == "events/date")
{
$htmlContent .= "<div class=\"hdr2\">" . $monthWords[$attrs["month"]] . ",
$attrs[year]</div></div>\n<div class=\"content\">";
}
}
}
}
An exmaple array for $startTags is as follows:
$startTags = array (
"content/section" => "<div class=\"content\">",
"text" => "<div class=\"txt2\">",
"list" => "<ul class=\"listtext\">",
"list/item" => "<li>",
"item" => "junk"
);
If you were trying to match up the item tag, then the loop would actually
print out the value of list/item and item, instead of breaking after it
found list/item.
This also assumes that the xml for this match is like this
<list>
<item>point 1</item>
<item>point 2</item>
</list>
--
Edit bug report at: http://bugs.php.net/?id=14220&edit=1
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]