Jump to content

upgrader

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by upgrader

  1. Still get the same error: With this code: curl_setopt($ch, CURLOPT_URL, 'myurl'); $result = curl_exec($ch); curl_close($ch); $result = (string)$result; $xml = simplexml_load_file($result); Edit: got it working, used simplexml_load_string instead.
  2. I'm trying to use data returned from a cURL request, the page returned is xml. When I try and load the returned data with simplexml_load_file I get the error saying simplexml does not recognize the file. The error: This is the xml response from curl: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><response><results><![CDATA[An error occured %s]]></results><status><![CDATA[]]></status></response> Here is a snippet of my code: curl_setopt($ch, CURLOPT_URL, 'myurl'); $result = curl_exec($ch); curl_close($ch); $xml = simplexml_load_file($result); (not the whole code, don't worry the cURL part works fine) Is there something special I have to do when trying to use data from a cURL request?
  3. Hi there, I have a database in which all the columns have collation as utf8_general_ci. Previously I was connecting to the database and inserting data without using SET names utf8, therefore a lot of the data has been inserted with the wrong encoding. The problem is all the data before using that has been stored incorrectly, and wierd characters are displayed instead. How can I convert that data into utf8? I think it must be mixed now, as I changed it to use set names utf8 so some data is correct.
  4. Hi there, I have this code to retrieve statistics from a page and cache them. The problem is when the site I am accessing goes down it just outputs a php error as expected. How can I rewrite this code so that if it doesn't manage to retrieve data from the site because it is down or it can't find the items it needs, it will display the last cached result instead? require_once("Lite.php"); $objCache = new Cache_Lite( array("cacheDir" => "cache/", "lifeTime" => 300) ); if ($top3 = $objCache->get("top3")) { // Debug: $top3 .= "<li>[Cached Result]</li>"; echo $top3; } else { $html = file_get_contents('http://badhausen.hlstatsx.com/?mode=players&game=css'); $dom = new domDocument; $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $x = new DomXPath($dom); $results = $x->query('//table/tr[position() >= 2 and position() <= 4]/td[2]/font/a'); foreach ($results as $result) { $top3 .= "<li>".$result->nodeValue."</li>\n"; } echo $top3; $objCache->save($top3, "top3"); }
×
×
  • 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.