Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
parse xml, varible not storing
Old 05-27-2009, 05:01 PM parse xml, varible not storing
rezzy's Avatar
Super Talker

Posts: 115
Location: in the interwebz
Trades: 0
I am parsing an xml file, for some reason the variable I am trying to pass isnt working. In this case its $x.

I am getting, Undefined variable: x on line 32
PHP Code:
<?php
$file 
"contactLast.xml";

function 
startTag($parser$data$x){

$text $data;

//checking for first row which contains data
  
if ($text == "ROW"){
      echo 
'work here';
      
$x 1;
     return 
$x;
      }
 else
      {
      
$x 0;
      return 
$x;
      }
$handle fopen('XXX.xml''a');

echo 
'<ul><li>' .$text'</li>';
fwrite($handle$text);
fclose($handle);
}

function 
contents($parser$data){

//information is in this area
$info $data;
echo 
'<ul><li>'.$info.'</li></ul>';

//below is line 32!
if ($x == '1') {
    echo 
'this is here';
}
    else  {echo 
'';}

if (
$info == "")
 {
    
$handle fopen('XXX.xml''a');
    
$text 'XXXXXXXXX';
    
fwrite($handle$text);
    
fclose($handle);
   }

else {
  
    
$handle fopen('XXX.xml''a');
    
$text $info;
    
fwrite($handle$text);
 }
  }

function 
endTag($parser$data){
 
$handle fopen('XXX.xml''a');
 
$text $data;
 echo 
'<li>'.$text.'</li></ul>';
 
fwrite($handle$text);
 
fclose($handle);
}



echo 
date('Y-m-d-=-g:i-s');
if (
unlink('XXX.xml')){
    
$x 1;
    echo 
$x;
}

$handle fopen('XXX.xml''a');
$text '<?xml version="1.0"?>';
fwrite($handle$text);
fclose($handle);

$xml_parser xml_parser_create();
/*if (!ini_set('max_execution_time', '300')){
    throw new Exception('failed');

}*/

xml_set_element_handler($xml_parser"startTag""endTag");
xml_set_character_data_handler($xml_parser"contents");
$fp fopen($file"r");
$data fread($fp20000);

if(!(
xml_parse($xml_parser$datafeof($fp)))){
    die(
"Error on line " xml_get_current_line_number($xml_parser));
}

xml_parser_free($xml_parser);
fclose($fp);
?>
__________________

Please login or register to view this content. Registration is FREE

Resnodesigns
rezzy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-27-2009, 08:56 PM Re: parse xml, varible not storing
markAtRitetek's Avatar
Experienced Talker

Posts: 32
Name: Mark Hudson
Location: Atlanta, GA
Trades: 0
x is not defined within the scope of that function so it is not available within that function. If you want to access x you either have to declare it as a global by typing "global $x;" at the top of your function, or you need to get the variable from another of your functions (or as a parameter in the contents function); there's any number of ways of doing it. Maybe there's some code I'm missing here, but that's what I see.
__________________
Mark Hudson
Ritetek Design

Please login or register to view this content. Registration is FREE
markAtRitetek is offline
Reply With Quote
View Public Profile Visit markAtRitetek's homepage!
 
Reply     « Reply to parse xml, varible not storing
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09677 seconds with 12 queries