Reply
XML feed to PHP
Old 07-30-2003, 11:42 AM XML feed to PHP
Novice Talker

Posts: 10
I have a medium sized video game website that uses PHP. I'm affiliated with dealtime.com and am trying to get the full functionality out of their service.

I want to include XML into my PHP rendered game reviews. They gave me an example URL to show the XML. Here is the URL/code/feed:

http://mb.dealtime.com/scripts/GSIsa...nd_Ruby/BEFID-

The URL does a simple HTML "GET" to show the XML. How would I take the XML feed and shoot it into my PHP?

Here is the syntax for the links if you needed:

http://mb.dealtime.com/scripts/GSIsa...A-yyy/UIP-zzz/

Thanks in advance.
search66 is offline
Reply With Quote
View Public Profile Visit search66's homepage!
 
When You Register, These Ads Go Away!
Old 07-30-2003, 12:43 PM
Experienced Talker

Posts: 33
Location: Portsmouth, UK
Later versions of PHP do include fairly solid XML support but I tend to find them bulky and overkill for what's needed. On my site I display latest XML feeds from several sites and the method I use, because it works fine for me, is roughly:

open the url using code similar to:

PHP Code:
$filereadbuffersize 4096;
$hFeed = @fopen($url_to_xml_feed,"r");
if(
$hFeed)
{
    
#    read specified amount into buffer
    
$contents = @fread($hFeed$filereadbuffersize);
    
fclose($hFeed); 
This reads 4k of data from the URL into a variable called contents. I then use simple strpos() lookups to find the XML tags I'm after and know exist and strip out the data from within.

Are you after specifics for your situation or did you just want this sort of average overview? If the former then you'd need to work out what, from the XML output, you actually wanted to retrieve.
neOnbubble is offline
Reply With Quote
View Public Profile Visit neOnbubble's homepage!
 
Old 07-30-2003, 12:46 PM
Novice Talker

Posts: 10
Well the URL->XML will change per page... Let me check out that snippet of code and see what happens. Thanks for the reply.
search66 is offline
Reply With Quote
View Public Profile Visit search66's homepage!
 
Old 07-30-2003, 12:58 PM
Novice Talker

Posts: 10
Strange. The concept sounds ideal, but when added to a test page; the code shows up and not the actual content.
search66 is offline
Reply With Quote
View Public Profile Visit search66's homepage!
 
Old 08-02-2003, 05:55 PM
Extreme Talker

Posts: 199
Location: Toronto
Hello,
I had this problem a while ago. I had to set up the XML feed for a PPC engine from http://www.browsehosts.com on my site
the browsehosts admin helped me set it up.
Here's the code which is on http://www.hostlead.com/toplist/ :

<?php

class Record {
var $url;
var $bid;
var $siteurl;
var $title;
var $description;
function Record ($aa) {
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}

function readDatabase($filename) {
$data = file_get_contents($filename);
//$data = implode("",file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLD ING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHIT E,1);
xml_parse_into_struct($parser,$data,$values,$tags) ;
xml_parser_free($parser);

// loop through the structures
foreach ($tags as $key=>$val) {
if ($key == "record") {
$ranges = $val;
for ($i=0; $i < count($ranges); $i+=2) {
$offset = $ranges[$i] + 1;
$len = $ranges[$i + 1] - $offset;
$tdb[] = parseit(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}

function parseit($mvalues) {
for ($i=0; $i < count($mvalues); $i++)
$record[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
return new Record($record);
}

$db = readDatabase("http://www.browsehosts.com/xmlsearch.php?keywords=budget+hosting&pageresult=2 0&startat=0&adult_filter=0&username=hostlead");

//function to print each result:
function printresult ($value,$name) {
print("
<li><strong><font size=\"2\"><a href='$value->url' target=\"_top\">$value->title</a></font></strong><br>$value->description
(Cost to advertiser: <a href=\"http://www.browsehosts.com/signup.php?referal=hostlead\">\$$value->bid</a>)<br></li>
");
}
//Actually print the stuff:
print "<font size=\"1em\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
print "<ol>\n"; //using an ordered list, with font setup above
array_walk($db,printresult);
print "</ol></font>\n";


?>

I know yours will be different but I hope this kind of helps you.

HostLead

Last edited by HostLead : 08-02-2003 at 05:57 PM.
HostLead is offline
Reply With Quote
View Public Profile Visit HostLead's homepage!
 
Old 08-02-2003, 08:11 PM
nakulgoyal's Avatar
#1Search Engine Optimizer

Posts: 376
Location: Chandigarh, India
I think I have a javascript to do it. PM me if u need it and will email it to you. or send the download link here in the forums.
__________________
Nakul Goyal
M.Sc (Information Technology), MCP, Brainbench 'MVP', BCIP, CIW Associate

* SEO Expert * IT Tips
nakulgoyal is offline
Reply With Quote
View Public Profile Visit nakulgoyal's homepage!
 
Old 08-04-2003, 08:35 AM
Novice Talker

Posts: 10
I'd love to check out that javascript if you have it. That was my next remidiation. 'Preciate the link.
search66 is offline
Reply With Quote
View Public Profile Visit search66's homepage!
 
Reply     « Reply to XML feed to PHP
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14308 seconds with 12 queries