0207100
-
Posts
5 -
Joined
-
Last visited
Never
Posts posted by 0207100
-
-
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]
<?php
function 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. -
[!--quoteo(post=352824:date=Mar 8 2006, 07:38 AM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 8 2006, 07:38 AM) [snapback]352824[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You missed a "slash"... This should do it...
[code]
function print_link_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>
echo '</p>';
}
[/code]
[/quote]
Hummm still not working and getting the parse error.
I even tried this:
[code]
function print_link_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>";
echo '</p>';
}
[/code]
and it also returned the parse error.
A stupid qustion on my behalf - in the original snip the var had a "." after it
[code]
function print_link_item($item) {
echo '<p>';
echo $item['Heading']."<br />\n";
echo $item['URI']."<br />\n";
echo $item['Description']."<br />\n";
echo $item['URL'];
echo '</p>';
}
[/code]
Why is a . not used in this example?
[code]
function print_link_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>
echo '</p>';
}
[/code] -
[!--quoteo(post=352807:date=Mar 8 2006, 07:08 AM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Mar 8 2006, 07:08 AM) [snapback]352807[/snapback][/div][div class=\'quotemain\'][!--quotec--]
function print_link_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>
echo '</p>';
}
[/quote]
Thanks for the help, I tried your code but have got the following error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
Im new to php and havent got a lot of experience. -
I need to take this array and have it print.
function print_link_item($item) {
echo '<p>';
echo $item['Heading']."<br />\n";
echo $item['URI']."<br />\n";
echo $item['Description']."<br />\n";
echo $item['URL'];
echo '</p>';
I want to have the Heading display the Link and when the user mouse overs the link instead of seeing the URI (real url) they will see the [URL] i want them to see.
How do I make the following work, I have fiddled with it and just cant make it work.
<a href="[URI]" target = '_blank' onMouseOver="window.status='[URL]'; return true;" onMouseOut="window.status=''; return true;">[Heading]</a>
Thanks
How do I Insert A Var In A URL Function
in PHP Coding Help
Posted
I need to insert 2 variables into a url that is part of a function and can't seem to do it. I know the code below has an error in it and am thinking I need to make $_SERVER[REMOTE_ADDR] and http://" . $_SERVER[SERVER_NAME] . $_SERVER[REQUEST_URI]; some sort of a var but am clueless how to do it.
Any help will be greatly appreciated.
The following code is a snip of the code.
[code]
return $children;
}
$url = "http://domain.com/xml_feed.php?p_id=1002&ad_count=5&channel=1&doc_offset=0&keyword=entertainment&limited=0&uip=$_SERVER[REMOTE_ADDR]&referring_page=$page_url ="http://" . $_SERVER[SERVER_NAME] . $_SERVER[REQUEST_URI];"; //URL of the XML FEED
$contents = file_get_contents($url);
$data = GetXMLTree ($contents);
[/code]