Results 1 to 15 of 15
-
11-17-2012, 07:55 PM #1Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
Want to pull data from a URL and display it using PHP/HTML
Alright, so I want to build a stats page for Killing Floor. Basically I want to pull data from a URL then using PHP I want to display this stats on a page formatting with HTML.
This is what I've tried so far, but it gives me errors.
Code:<?php //Passing the XML $data = file_get_contents('steamcommunity.com/id/lblanchardiii/statsfeed/1250/?xml=1&schema=1'); $stats = simplexml_load_file($data); //----------------------- //Passing a filename $stats = simplexml_load_file('steamcommunity.com/id/lblanchardiii/statsfeed/1250/?xml=1&schema=1', null, true); ?>
Code:Warning: file_get_contents(steamcommunity.com/id/lblanchardiii/statsfeed/1250/?xml=1&schema=1) [function.file-get-contents]: failed to open stream: No such file or directory in /home2/tdnclan/public_html/kf-stats/index.php on line 4 Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "" in /home2/tdnclan/public_html/kf-stats/index.php on line 5 Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "steamcommunity.com/id/lblanchardiii/statsfeed/1250/?xml=1&schema=1" in /home2/tdnclan/public_html/kf-stats/index.php on line 8
However that doesn't seem to work. I then just saved the XML file to the web server, then used the direct file name in the code above instead of the URL.
Code:<?php //Passing the XML $data = file_get_contents('1250.xml'); $stats = simplexml_load_file($data); //----------------------- //Passing a filename $stats = simplexml_load_file('1250.xml', null, true); ?>
Code:Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "<?xml version="1.0" encoding="UTF-8" standalone="yes"?><statsfeed><steamID64>76561198035683889</steamID64><stats><ite in /home2/tdnclan/public_html/kf-stats/index.php on line 5
Just realized I am using simplexml_load_file() in the code above, even though the tutorial said to use SimpleXMLElement(), but since that wasn't working I assumed I needed to use something to pull a file remotely since the file wasn't stored physically. Still not working as this is the error I am getting, with the file stored locally.
Code:<?php //Passing the XML $data = file_get_contents('1250.xml'); $stats = SimpleXMLElement($data); //----------------------- //Passing a filename $stats = SimpleXMLElement('1250.xml', null, true); ?>
Code:Fatal error: Call to undefined function SimpleXMLElement() in /home2/tdnclan/public_html/kf-stats/index.php on line 5
-
11-17-2012, 08:15 PM #2Junior Guru Wannabe
- Join Date
- Nov 2004
- Posts
- 71
for "file_get_contents" you need to supply the protocol like 'http://' so it knows where to get the data from.
As for the other example you used, looks like you don't have the required XML functions installed on your server.
-
11-17-2012, 08:27 PM #3Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
Gonna test out that http:// thing, but as for the required XML functions... can you be a little more specific on that?
I'm running CentOS 5.8 w/ WHM/cPanel...
Apache version 2.2.23
PHP version 5.3.18
MySQL version 5.1.65-cll
Architecture x86_64
Perl version 5.8.8
Kernel version 2.6.18-308.11.1.el5
Going to do some research on it now.
-
11-17-2012, 08:30 PM #4Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
Thinking this is what I need to compile apache with; http://www.php.net/manual/en/ref.xmlrpc.php
Doing that as I type this.
-
11-17-2012, 08:33 PM #5Web Hosting Master
- Join Date
- Aug 2001
- Posts
- 5,597
Try
PHP Code:$stats = new SimpleXMLElement('1250.xml', null, true);
-
11-17-2012, 08:34 PM #6Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
-
11-17-2012, 08:37 PM #7Web Hosting Master
- Join Date
- Aug 2001
- Posts
- 5,597
What PHP version do you use? It should be enabled by default http://www.php.net/manual/en/simplexml.installation.php unless you disabled it
-
11-17-2012, 08:40 PM #8Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
5.3.18 and as far as I know I haven't disabled it. I will check that real quick though.
-
11-17-2012, 08:42 PM #9Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
Apparently it should be enabled.
Code:a:40:{i:0;s:4:"Core";i:1;s:4:"date";i:2;s:4:"ereg";i:3;s:6:"libxml";i:4;s:7 :"openssl";i:5;s:4:"pcre";i:6;s:7:"sqlite3";i:7;s:4:"zlib";i:8;s:6:"bcmath" ;i:9;s:8:"calendar";i:10;s:5:"ctype";i:11;s:4:"curl";i:12;s:3:"dom";i:13;s: 4:"hash";i:14;s:6:"filter";i:15;s:3:"ftp";i:16;s:2:"gd";i:17;s:3:"SPL";i:18 ;s:5:"iconv";i:19;s:7:"session";i:20;s:4:"json";i:21;s:8:"mbstring";i:22;s: 5:"mysql";i:23;s:6:"mysqli";i:24;s:5:"posix";i:25;s:10:"Reflection";i:26;s: 8:"standard";i:27;s:4:"imap";i:28;s:9:"SimpleXML";i:29;s:7:"sockets";i:30;s :4:"exif";i:31;s:9:"tokenizer";i:32;s:3:"xml";i:33;s:9:"xmlreader";i:34;s:9 :"xmlwriter";i:35;s:8:"cgi-fcgi";i:36;s:3:"PDO";i:37;s:10:"pdo_sqlite";i:38 ;s:6:"SQLite";i:39;s:17:"Zend Guard Loader";}
-
11-17-2012, 08:44 PM #10Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
Oh wait a minute, I used this code here and it's reporting a blank page; which I think is what it should do right?
Code:<?php //Passing the XML $data = file_get_contents('1250.xml'); $stats = new SimpleXMLElement($data); //----------------------- //Passing a filename $stats = new SimpleXMLElement('1250.xml', null, true); ?>
-
11-17-2012, 08:46 PM #11Web Hosting Master
- Join Date
- Aug 2001
- Posts
- 5,597
A blank page would be fine. Do you get a valid object back?
-
11-17-2012, 08:48 PM #12Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
-
11-17-2012, 08:55 PM #13Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
Okay, I think this is not going to work and I'm going to have to take a different approach. Maybe this isn't an XML file like I originally thought it was. Let me explain.
This is the rest of the code I've since placed under the code I posted above.
Code:<?php // load SimpleXML $stats = new SimpleXMLElement('1250.xml', null, true); echo <<<EOF <table> <tr> <th>Kills</th> </tr> EOF; foreach($stats as $stats) // loop through our stats { echo <<<EOF <tr> <td>{$stats->kills}</td> </tr> EOF; } echo '</table>'; ?>
Code:<statsfeed> <steamID64>76561198035683889</steamID64> <stats> <item> <APIName>kills</APIName> <value>35232</value> <displayName>Kills</displayName> </item> <item> <APIName>damagehealed</APIName> <value>19944</value> <displayName>Damage Healed</displayName> </item>
Back to the drawing board now.
-
11-17-2012, 09:34 PM #14Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
Getting somewhere now... Seems I just needed to think about what I was doing first.
Code:<?php //Passing the XML $data = file_get_contents('1250.xml'); $stats = new SimpleXMLElement($data); //----------------------- //Passing a filename $stats = new SimpleXMLElement('1250.xml', null, true); ?> <?php // load SimpleXML $stats = new SimpleXMLElement('1250.xml', null, true); echo <<<EOF <table> <tr> <th>Stat</th> <th>value</th> <th>Display Name</th> </tr> EOF; foreach($stats as $stats) // loop through our stats { echo <<<EOF <tr> <td>{$stats->item->APIName}</td> <td>{$stats->item->value}</td> <td>{$stats->item->displayname}</td> </tr> EOF; } echo '</table>'; ?>
http://steamcommunity.com/id/lblanch...xml=1&schema=1
This is what shows when the above code is pulls the data from above (but a physical file instead of the URL)
Code:Stat value Display Name kills 35232 winwestlondonnormal 1
the top half of the xml file
Code:<statsfeed> <steamID64>76561198035683889</steamID64> <stats> <item> <APIName>kills</APIName> <value>35232</value> <displayName>Kills</displayName> </item>
Code:</stats> <achievements> <item> <APIName>winwestlondonnormal</APIName> <value>1</value> <displayName>
-
11-17-2012, 10:30 PM #15Junior Guru Wannabe
- Join Date
- Aug 2007
- Posts
- 72
Okay, I think I am going to take a different approach this. Instead of the way I'm doing it now (printing the data), I'm going to try to map the data so I can use it that way. Now where do I start on that? Google to the rescue.
Similar Threads
-
php break up data by months to display?
By lexington in forum Programming DiscussionReplies: 14Last Post: 05-05-2009, 03:11 AM -
(PHP) Script won't display any data
By calidude in forum Programming DiscussionReplies: 21Last Post: 08-08-2008, 12:50 AM -
Display text when a link is clicked (javascript/php/html)
By liquidgoat in forum Programming DiscussionReplies: 1Last Post: 10-22-2005, 03:05 AM -
Display data in 3 columns in PHP
By Mondeo in forum Programming DiscussionReplies: 12Last Post: 09-08-2004, 10:42 PM -
Small task (php/mysql), pull data from db and list it in A-Z listing
By mrsam in forum Employment / Job OffersReplies: 8Last Post: 07-27-2004, 06:26 AM