|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-11-25 23:34 UTC] tim dot lokot at s1 dot com dot au
[2001-11-26 02:59 UTC] mfischer@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 06:00:01 2025 UTC |
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>