attaboy Posted February 7, 2013 Share Posted February 7, 2013 This is my XML: <?xml version="1.0" encoding="utf-8"?> <links> <category desc="XAML Related"> <link url="http://longhorn.msdn.microsoft.com" desc="Longhorn SDK home" title="Source of Longhorn" /> <link url="http://longhornblogs.com" desc="Longhorn Blogs" /> <link url="http://xamlblogs.com" desc="XAML Blogs" /> <link url="http://www.xamlong.com" desc="Xamlong.com" /> <link url="http://www.mobiform.com" desc="Mobiform" /> <link url="http://www.zaml.com" desc="Zaml.com" /> <link url="http://www.zaml.net" desc="Xaml.net" /> </category> <category desc="XAML Related"> <link url="http://jimslounge.com" desc="Jim's Lounge" title="Source of fun" /> <link url="http://longhorn.com" desc="Longhorn Cheese" /> . . . </xml> This is my php: <?php function startElemHandler($parser, $name, $attribs) { if (strcasecmp($name, "links") == 0) { echo "<div id='linklist'>\n"; } if (strcasecmp($name, "category") == 0) { $desc = $attribs['desc']; echo "<p>$desc</p><ul>\n"; } if (strcasecmp($name, "link") == 0) { $url = $attribs['url']; $desc = $attribs['desc']; [b]$title = $attribs['title'];[/b] echo "<li><a href='$url' target='_blank'"; if ($title != " ") echo " title='$title'"; echo ">"; if ($desc == " ") echo "$url"; else echo "$desc"; echo "</a></li>"; } } function endElemHandler($parser, $name) { if (strcasecmp($name, "links") == 0) { echo "</div>\n"; } if (strcasecmp($name, "category") == 0) { echo "</ul>\n"; } } $parser = xml_parser_create(); xml_set_element_handler($parser, 'startElemHandler', 'endElemHandler'); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); $strXML = implode("",file("links.xml")); xml_parse($parser, $strXML); xml_parser_free($parser); ?> I've created variables to hold values of all the attributes. $url, and $desc don't generate a warning why does $title? Link to comment https://forums.phpfreaks.com/topic/274134-notice-undefined-index-title-in-cxampphtdocssaxlinksphp-on-line-14/ Share on other sites More sharing options...
requinix Posted February 7, 2013 Share Posted February 7, 2013 Because not all of those s have titles. Link to comment https://forums.phpfreaks.com/topic/274134-notice-undefined-index-title-in-cxampphtdocssaxlinksphp-on-line-14/#findComment-1410615 Share on other sites More sharing options...
attaboy Posted February 7, 2013 Author Share Posted February 7, 2013 Sure enough, thanks! Link to comment https://forums.phpfreaks.com/topic/274134-notice-undefined-index-title-in-cxampphtdocssaxlinksphp-on-line-14/#findComment-1410617 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.