Jump to content

******NEW guess i am just stuck*$*$*$**$


cardio5643

Recommended Posts

This code creates and writes to file

 

 <?php
       $xmlFile = "../etc/someXMLfile.xml";
       $xmlHandle = fopen($xmlFile, "w");
       fwrite($xmlHandle, 'test');
       fclose($xmlHandle);
    ?>

This code does create, but does NOT write to file

    <?php
       $xmlFile = "../etc/someXMLfile.xml";
       $xmlHandle = fopen($xmlFile, "w");
       $flashXML = simplexml_load_string('<root><number>1</number></root>');
       fwrite($xmlHandle, 'test');
       fclose($xmlHandle);
    ?>

This is the goal code:

<?php
$flashRAW = file_get_contents("php://input");
$xml = simplexml_load_string($flashRAW);
$str = $xml->number->{0};
$xmlFile = "../etc/someXMLfile.xml";
$xmlHandle = fopen($xmlFile, "w");
fwrite($xmlHandle, $str);
fclose($xmlHandle);
?>

 

Now, who can tell me what I am doing wrong - because I have tried with no luck.

 

                                                                        h e l p

Link to comment
Share on other sites

Also,

 

<?php
$flashRAW = file_get_contents("someXMLfile.xml");
$xml = simplexml_load_string($flashRAW);
$str = $xml->number;
$xmlFile = "test.xml";
$xmlHandle = fopen($xmlFile, "w");
fwrite($xmlHandle, $str);
fclose($xmlHandle);
?>

 

That code works fine for me... I changed the output file name so I wouldn't overwrite the other one as you had them both named someXMLfile.xml

 

I also chaged this line

 

$str = $xml->number->{0};

 

to

 

$str = $xml->number;

 

since there is only one number element in your first examples

 

I end up with a file called test.xml with a 1 in it

Link to comment
Share on other sites

You're going to annoy the moderators if you keep creating new topics.

 

    <?php
       $xmlFile = "../etc/someXMLfile.xml"; // line 1
       $xmlHandle = fopen($xmlFile, "w"); // line 2
       $flashXML = simplexml_load_string('<root><number>1</number></root>'); // line 3
       fwrite($xmlHandle, 'test'); // line 4
       fclose($xmlHandle); // line 5
    ?>

 

The reason that creates but does not write to the file is simple.  Lines 1 and 2 are executed, line 3 is crashing and terminating the program.

 

    <?php
       $xmlFile = "../etc/someXMLfile.xml";
       $xmlHandle = fopen($xmlFile, "w");
       fwrite($xmlHandle, 'test');
       fclose($xmlHandle);
       $flashXML = simplexml_load_string('<root><number>1</number></root>');
    ?>

Try that and you're file will be created.

 

Now do like I said in your other-other thread and validate your XML before sending it to SimpleXML.

Link to comment
Share on other sites

You're going to annoy the moderators if you keep creating new topics.

 

    <?php
       $xmlFile = "../etc/someXMLfile.xml"; // line 1
       $xmlHandle = fopen($xmlFile, "w"); // line 2
       $flashXML = simplexml_load_string('<root><number>1</number></root>'); // line 3
       fwrite($xmlHandle, 'test'); // line 4
       fclose($xmlHandle); // line 5
    ?>

 

The reason that creates but does not write to the file is simple.  Lines 1 and 2 are executed, line 3 is crashing and terminating the program.

 

    <?php
       $xmlFile = "../etc/someXMLfile.xml";
       $xmlHandle = fopen($xmlFile, "w");
       fwrite($xmlHandle, 'test');
       fclose($xmlHandle);
       $flashXML = simplexml_load_string('<root><number>1</number></root>');
    ?>

Try that and you're file will be created.

 

Now do like I said in your other-other thread and validate your XML before sending it to SimpleXML.

 

Obviously it is crashing, but I am not trying to write the word test to a file, i am trying to write the contents of the xml, meaning where the word test is i would have something like $xml->number, but that does not work either. so to prove that the simplexml JUST BEING IN THE FILE crashes the file, i put it in there but kept the text 'test' to write in order to debug. my xml looks validated to me - but maybe someone knows better

 

and i do not mean to be a bother, my first thread was dying, my second didnt make sense, so this is my third. will not do again.

Link to comment
Share on other sites

Also,

 

<?php
$flashRAW = file_get_contents("someXMLfile.xml");
$xml = simplexml_load_string($flashRAW);
$str = $xml->number;
$xmlFile = "test.xml";
$xmlHandle = fopen($xmlFile, "w");
fwrite($xmlHandle, $str);
fclose($xmlHandle);
?>

 

That code works fine for me... I changed the output file name so I wouldn't overwrite the other one as you had them both named someXMLfile.xml

 

I also chaged this line

 

$str = $xml->number->{0};

 

to

 

$str = $xml->number;

 

since there is only one number element in your first examples

 

I end up with a file called test.xml with a 1 in it

 

but i am not getting my contents from a file, i am getting them from an asynchronous javascript routine.

Link to comment
Share on other sites

simplexml_load_string();

 

returns an object... is is not the xml string anymore, but an object representing it. You would need to regenerate the xml placing into it the contents from the simplexml object.

 

My question would be, why are you loading it into a variable with file_get_contents() only to write it right back into the same format?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.