0207100 Posted March 10, 2006 Share Posted March 10, 2006 I am wanting to run this scrip so that the code is called as an include_once and then get the a variable and finally prints the items.The page is built by calling 5 different dynamic sections.My Thought was I could include this in the header of the page as a php file:[code]<?phpfunction GetXMLTree ($xmldata){ // we want to know if an error occurs ini_set ('track_errors', '1'); $xmlreaderror = false; $parser = xml_parser_create ('ISO-8859-1'); xml_parser_set_option ($parser, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0); if (!xml_parse_into_struct ($parser, $xmldata, $vals, $index)) { $xmlreaderror = true; echo "error"; } xml_parser_free ($parser); if (!$xmlreaderror) { $result = array (); $i = 0; if (isset ($vals [$i]['attributes'])) foreach (array_keys ($vals [$i]['attributes']) as $attkey) $attributes [$attkey] = $vals [$i]['attributes'][$attkey]; $result [$vals [$i]['tag']] = array_merge ($attributes, GetChildren ($vals, $i, 'open')); } ini_set ('track_errors', '0'); return $result;}function GetChildren ($vals, &$i, $type){ if ($type == 'complete') { if (isset ($vals [$i]['value'])) return ($vals [$i]['value']); else return ''; } $children = array (); // Contains node data /* Loop through children */ while ($vals [++$i]['type'] != 'close') { $type = $vals [$i]['type']; // first check if we already have one and need to create an array if (isset ($children [$vals [$i]['tag']])) { if (is_array ($children [$vals [$i]['tag']])) { $temp = array_keys ($children [$vals [$i]['tag']]); // there is one of these things already and it is itself an array if (is_string ($temp [0])) { $a = $children [$vals [$i]['tag']]; unset ($children [$vals [$i]['tag']]); $children [$vals [$i]['tag']][0] = $a; } } else { $a = $children [$vals [$i]['tag']]; unset ($children [$vals [$i]['tag']]); $children [$vals [$i]['tag']][0] = $a; } $children [$vals [$i]['tag']][] = GetChildren ($vals, $i, $type); } else $children [$vals [$i]['tag']] = GetChildren ($vals, $i, $type); // I don't think I need attributes but this is how I would do them: if (isset ($vals [$i]['attributes'])) { $attributes = array (); foreach (array_keys ($vals [$i]['attributes']) as $attkey) $attributes [$attkey] = $vals [$i]['attributes'][$attkey]; // now check: do we already have an array or a value? if (isset ($children [$vals [$i]['tag']])) { // case where there is an attribute but no value, a complete with an attribute in other words if ($children [$vals [$i]['tag']] == '') { unset ($children [$vals [$i]['tag']]); $children [$vals [$i]['tag']] = $attributes; } // case where there is an array of identical items with attributes elseif (is_array ($children [$vals [$i]['tag']])) { $index = count ($children [$vals [$i]['tag']]) - 1; // probably also have to check here whether the individual item is also an array or not or what... all a bit messy if ($children [$vals [$i]['tag']][$index] == '') { unset ($children [$vals [$i]['tag']][$index]); $children [$vals [$i]['tag']][$index] = $attributes; } $children [$vals [$i]['tag']][$index] = array_merge ($children [$vals [$i]['tag']][$index], $attributes); } else { $value = $children [$vals [$i]['tag']]; unset ($children [$vals [$i]['tag']]); $children [$vals [$i]['tag']]['value'] = $value; $children [$vals [$i]['tag']] = array_merge ($children [$vals [$i]['tag']], $attributes); } } else $children [$vals [$i]['tag']] = $attributes; } } return $children;}$url = "http://text.dynamicmedia.us/ads/xml_feed.php?p_id=1002&ad_count=10&channel=1&doc_offset=0&keyword=creditcards&limited=0&uip=82.35.20.94&referring_page=http://dynamicmedia.us/index.php"; //URL of the XML FEED$contents = file_get_contents($url);$data = GetXMLTree ($contents);function print_ad_item($item) { echo '<p>'; echo $item['Heading']."<br />\n"; echo $item['URI']."<br />\n"; echo $item['Description']."<br />\n"; echo $item['URL']; echo '</p>';}function print_line_item($item) { echo '<p>'; echo "<a href=\"{$item['URI']}\" target =\"_blank\" onMouseOver=\"window.status='{$item['URL']}'; return true;\"onMouseOut=\"window.status=''; return true;\">{$item['Heading']}</a><br />\n"; echo '<br />';}function print_textad_item($item) { echo '<p>'; echo "<a href=\"{$item['URI']}\" target =\"_blank\" onMouseOver=\"window.status='{$item['URL']}'; return true;\"onMouseOut=\"window.status=''; return true;\">{$item['Heading']}</a><br />\n"; echo $item['Description']."<br />\n"; echo '</p>';}$textad = $data['Ads']['Listing'];?>[/code]The line:[code]$url = "http://text.dynamicmedia.us/ads/xml_feed.php?p_id=1002&ad_count=10&channel=1&doc_offset=0&keyword=creditcards&limited=0&uip=82.35.20.94&referring_page=http://dynamicmedia.us/index.php"; //URL of the XML FEED[/code]could be inserted in the page as it is built since I need to insert a variable or two - specifically a keyword, the referring page, and the visitors IP address, I thought I could do this outside of the php file i am including in the header. But.... im not sure how that would be done?Then I wanted to insert the following to print the results into 2 different areas a the dynamically created page.<?print_line_item($textad[0]);print_textad_item($textad[1]);print_textad_item($textad[2]);print_textad_item($textad[3]);print_textad_item($textad[4]);print_textad_item($textad[5]);print_textad_item($textad[6]);print_textad_item($textad[7]);print_textad_item($textad[8]);print_textad_item($textad[9]);?>The problem I have is i only get an error - no other details. I am a total nuuuubie to php and think im a bit over my head on this one.Any help will be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/4600-calling-script-in-page-build/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.