Click here to get back home

getting "1" in my temp.xml when using fwrite

 HomeNewsGroups | Search
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
getting "1" in my temp.xml when using fwrite alexus 11-11-2008
Posted by alexus on November 11, 2008, 1:17 am
Please log in for more thread options
fwrite(fopen('temp.xml','w+'),
print_r(simplexml_load_string(curl_exec($test))),true);

i for some reason get "1" inside of my temp.xml

Posted by Erwin Moller on November 11, 2008, 4:20 am
Please log in for more thread options
alexus schreef:
> fwrite(fopen('temp.xml','w+'),
> print_r(simplexml_load_string(curl_exec($test))),true);
>
> i for some reason get "1" inside of my temp.xml

Hi Alexus,
You are making a mess of thing in more than 1 way.
First you try to write your code in 1 line, making it hard to follow
(for you too appearantly).
Second: You use print_r() in a very strange way.
Third: You don't close your filehandles.


Why don't you open an handle first? How will you close this stream?
And what does that last true mean?
Read here:
http://nl3.php.net/manual/en/function.fwrite.php
The third argument is the length, not a boolean.

Try this:

$myHandle = fopen('temp.xml','w+');
$myData = simplexml_load_string(curl_exec($test));
echo "Going to write:<pre>";
print_r($myData );
echo "</pre>";
fwrite($myHandle ,$myData);
fclose($myHandle);


Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Posted by Jerry Stuckle on November 11, 2008, 6:43 am
Please log in for more thread options
alexus wrote:
> fwrite(fopen('temp.xml','w+'),
> print_r(simplexml_load_string(curl_exec($test))),true);
>
> i for some reason get "1" inside of my temp.xml

simplexml doesn't cooperate with print_r() or var_dump().

Instead of doing all this in one statement, first fetch the string with
curl_exec() and ensure it worked OK. Then call simplexml_load_string().

Rather than using print_r(), iterate through the child elements. See
http://www.php.net/manual/en/function.simplexml-element-children.php for
an example on how to iterate the child nodes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Similar ThreadsPosted
Temp downgrading of PHP version. May 11, 2005, 6:16 pm
DROP TEMP TABLES October 14, 2005, 6:57 am
Cookie not appearing in Temp Folder June 27, 2005, 12:07 am
what does PHP do with temp files uploaded to the server? June 16, 2008, 1:38 pm
Saving Temp Files in Shared Memory November 28, 2005, 7:33 am
fopen(temp/pglog.20050106.log): failed to open stream: Permission denied January 6, 2005, 7:30 am
fwrite March 23, 2005, 10:30 pm
PHP fwrite EOF? October 13, 2006, 1:55 pm
fwrite for log January 7, 2008, 3:36 am
UTF-8 fwrite problem April 13, 2005, 11:50 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap