cURL Help


#1

Hello all,

I’m trying to get a script to work with cURL instead of fopen in my php script, and I’m having a hard time getting it to work (I’m not familiar with cURL whatsoever). The error I’m getting is:

Fatal error: Call to undefined method DOMDocument::curl_exec() in /home/.masago/roostj2010/mirollercoast.com/sidebar/todayinthepark.php on line 10

And my code is:

<?php $url = "http://www.weather.gov/data/current_obs/KMKG.xml"; $doc = new DOMDocument(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $doc->curl_exec($ch); $obs = $doc->getElementsByTagName( "current_observation" ); foreach( $obs as $cobs ) { $weather = $cobs->getElementsByTagName( "weather" ); $wthr = $weather->item(0)->nodeValue; $image = $cobs->getElementsByTagName( "icon_url_name" ); $wimg = $image->item(0)->nodeValue; $temps = $cobs->getElementsByTagName( "temp_f" ); $temp = $temps->item(0)->nodeValue; } ?>

Any help would be greatly appreciated, as I don’t know what I can do to solve this problem!

Thanks,

-Jon Roost
www.mirollercoast.com
Dreamhost Customer


#2

I’m not familiar with the XML syntax in your code sample, but I am aware of how to make the cURL part of it work:[code]$url = “http://www.weather.gov/data/current_obs/KMKG.xml”;
$doc = new DOMDocument();
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
$file_contents = curl_exec($ch);
curl_close($ch);
$doc->$file_contents;

// script continues…[/code]-- si-blog
Max discount on any plan with promocode SCJESSEYTOTAL


#3

Pay attention to the error messages.

[b]Call to undefined method DOMDocument::curl_exec()[/b]Or to put that another way: curl_exec() is not a method of DOMDocument.

BTW Simon neither is $file_contents.

You might want to stop and think about what you want to do and read the documentation to figure out how to do it.

For example check out the list of methods provided by DOMDocument.

Do you see any about loading documents from strings?

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#4

[quote]Or to put that another way: curl_exec() is not a method of DOMDocument.

BTW Simon neither is $file_contents.[/quote]
I indicated above that I was unfamiliar with the XML stuff in the example, but it seems to me that since $file_contents is a string that contains the XML file, the OP is looking for something like:$doc->loadXML($file_contents);Reference: DOMDocument->loadXML()

si-blog
Max discount on any plan with promocode SCJESSEYTOTAL