Jump to content

upgrader

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

upgrader's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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"); }
  5. How does it work though? How does that cache the results from my script above?
  6. Hmmm, I don't really think that will work as that script above is part of a wordpress page so won't it screw that up? Can anyone else help?
  7. Thanks for your input... notice how I was asking for a good caching method in this situation... @dreamwest: what does that do etc? Could you explain it?
  8. Hi there, I've never really done any caching at all so I'm looking for suggestions for caching the results of this script so that instead of it running everytime the page loads it only say once every hour. $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) { echo "<li>".$result->nodeValue."</li>\n"; }
  9. Hi there I have wrote the code below to search the table on the URL and pick out the name value in rows 2-4, however it is not very efficient as it still does a foreach on every single row. $html = file_get_contents('http://badhausen.hlstatsx.com/?mode=players&game=css'); $dom = new domDocument; $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $tables = $dom->getElementsbyTagName('table'); $rows = $tables->item(->getElementsByTagName('tr'); $count = 1; foreach ($rows as $row) { if($count >= 2 && $count <=4) { $cols = $row->getElementsByTagName('td'); echo "<li>".$cols->item(1)->nodeValue.'</li>'; } $count++; } How could I optimise it?
  10. Hi there, I'm just learning how to use DOMDocument to grab items from HTML documents over using Regex. I'm stuck trying to work out how I would get the first 3 names on the Player Rankings table here: http://badhausen.hlstatsx.com/?mode=players&game=css Thanks for any help
  11. You might want to remove your mysql host, username and password from the post with the code...
  12. Have it so when I open the download.php page containing the script in the post above it executes it and downloads the files rather than me running the command php download.php in SSH.
  13. Surely thats the same thing as directly opening the page??
×
×
  • 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.