hello all
since many many servers do not allow the fopen - i have to replace this - Can you assist me here; That would be great:
<?php
//this is a simple stand-alone PHP example script
//
function searchAmazon($search,$searchtype='AsinSearch') {
//you normally would like to change the following two variables
//(but the script should also work as it is)
//$search ='machiavelli'; //replace this with your own search term, you can give upto 3 terms separated by '%20' like 'cat%20dog', a '+' should also work instad of %20
//$search ='title:"civil+engineering"'; //replace this with your own search term, you can give upto 3 terms separated by '%20' like 'cat%20dog', a '+' should also work instad of %20
$associates_id='chipdir'; //replace this with your own associate id
//get one from http://associates.amazon.com/exec/panama/associates/apply
//--You don't have to change anything after this line, to start earning money.--
$dev_token='D2WMCOIPS9D14E'; //replace this with your own developer token if you like
//get one from http://associates.amazon.com/exec/panama/associates/join/developer/application.html
//you don't have to change this token unless you change the code a lot it seems:
//http://forums.prospero.com/n/mb/message.asp?webtag=am-assocdevxml&msg=378.1&ctx=0
$mode='books'; //change this if you want to offer something else as books
//other modes are:
//mode=baby (Baby)
//mode=books (Books)
//mode=classical (Classical Music)
//mode=dvd (DVD)
//mode=electronics (Electronics)
//mode=garden (Outdoor Living)
//mode=kitchen (Kitchen & Housewares)
//mode=magazines (Magazines)
//mode=music (Popular Music)
//mode=pc-hardware (Computers)
//mode=photo (Camera & Photo)
//mode=software (Software)
//mode=tools (Tools & Hardware)
//mode=toys (Toys & Games)
//mode=vhs (Video)
//mode=videogames (Computer & Video Games)
# search parameters:
$type='heavy'; //or lite;
$page=1;
$file="onca/xml3?".
"dev-t=$dev_token".'&'.
"f=xml".'&'.
urlencode($searchtype).'='.urlencode($search).'&'.
"mode=$mode".'&'.
"page=$page".'&'.
"t=$associates_id".'&'.
"type=$type".'&'.
"v=1";
//Please note that:
//- /onca/xml3 is the pathname of the URL
//- ? denotes the spot where the arguments start
//- that all arguments consist of 'argument_name=value' and that I have put them in alphabetical order
//- that '&' seperates the arguments
//you can also add:
//- page=1 for result entries 1..10
//- page=2 for result entries 11..20
//- etc.
//Each query result will contain only up to 10 entries. If you want to show more than 10 results, you will have to show several pages with results until you get a result with 0..9 entries, but when it's 0 you'll get an error message instead.
//To search for ASIN's, replace the KeywordSearch line by AsinSearch=<ASIN>,<another ASIN> upto 30 for lite and 10 for heavy searches.
//To search for UPC's use instead: UpcSearch=<upc>,<upc>.
//You can also use:
//- AuthorSearch =.. (only for mode=books)
//- ArtistSearch =.. (only for mode=music,classical)
//- ActorSearch =.. (only for mode=dvd,vhs,video)
//- DirectorSearch =.. (only for mode=dvd,vhs,video)
//- ManufacturerSearch=.. (only for mode=electronics,kitchen,videogames,software,photo,pc-hardware)
//- SimilaratiesSearch=ASIN (no mode)
//Amazon lists (in the lite version) per book a record like:
// <Details url="http://www.amazon.com/exec/obidos/redirect?tag=chipdir%26creative=D2WMCOIPS9D14E%26camp=2025%26link_code=xm2%26path=ASIN/039480001X">
// <Asin>039480001X</Asin>
// <ProductName>The Cat in the Hat</ProductName>
// <Catalog>Book</Catalog>
// <Authors>
// <Author>Seuss</Author>
// <Author>Theodor Seuss Geisel</Author>
// <Author>Dr. Seuss</Author>
// </Authors>
// <ReleaseDate>June, 1957</ReleaseDate>
// <Manufacturer>Random House (Merchandising)</Manufacturer>
// <ImageUrlSmall>http://images.amazon.com/images/P/039480001X.01.THUMBZZZ.jpg</ImageUrlSmall>
// <ImageUrlMedium>http://images.amazon.com/images/P/039480001X.01.MZZZZZZZ.jpg</ImageUrlMedium>
// <ImageUrlLarge>http://images.amazon.com/images/P/039480001X.01.LZZZZZZZ.jpg</ImageUrlLarge>
// <ListPrice>$8.99</ListPrice>
// <OurPrice>$8.99</OurPrice>
// <UsedPrice>$0.50</UsedPrice>
// </Details>
//
//in case there was an error or nothing was found Amazon will return something like:
//<ProductInfo><ErrorMsg>There are no exact matches for the search.</ErrorMsg></ProductInfo>
echo htmlentities($file)."<br />";
return getAmazon($file);
}
//global variables:
$totalresults='unknown';
$show_xml=false; //change to true to debug the XML code
//get the data from amazon
function getAmazon($file) {
global $show_xml;
global $totalresults;
if ($hf=fopen("http://xml.amazon.com/$file",'r')) { //open a file from Amazon
while ($line=fgets($hf,10000)) { //handle each line of XML
$s.=$line;
}
if ($show_xml) { //print the raw XML instead of parsing it into an array?
print "<pre>".htmlentities($s)."</pre>\n";
}
}
else die("Can't open socket for xml.amazon.com.<br>\n");
return xml2array($s);
}
//convert an XML-string to an array
function xml2array($s) {
if ($Atmp1=explode('>',$s,2) and ereg('^<\?(xml .*)\?$',$Atmp1[0],$Atmp2)) {
$A['xml']=$Atmp2[1];
xml2array_sub($A,$Atmp1[1]);
}
return $A;
}
function xml2array_sub(&$A,$s) {
global $error_msg;
for ($c=0;ereg('<([^<>/ ]*)( [^<>]*)?/>(.*)',$s,$Atmp1) or
ereg('<([^<>/ ]*)( [^<>]*)?>(.*)',$s,$Atmp1) and
$Atmp2=explode('</'.$Atmp1[1].'>',$Atmp1[3],2);++$c) {
$E=array();
$tag=$Atmp1[1];
if ($Atmp1[2]) {
$Atmp3=explode(' ',substr($Atmp1[2],1));
foreach ($Atmp3 as $d) {
$Atmp4=explode('=',$d,2);
$Atmp4[1]=ereg_replace('^"(.*)"$','\1',$Atmp4[1]);
$E[$Atmp4[0]]=$Atmp4[1];
}
}
if ($Atmp2) {
if (!xml2array_sub($E,$Atmp2[0])) {
$E=$Atmp2[0];
}
$s=$Atmp2[1]; //rest of the xml-code
$Atmp2=false;
}
else {
$s=$Atmp1[3]; //rest of the xml-code
}
if (isset($A[$tag])) { //does it already exist? 20040715: isset() added
if (!is_array($A[$tag]) or !$A[$tag][0]) { //not already a numberically indexed array?
$Atag=$A[$tag]; //remove element again
unset($A[$tag]);
$A[$tag][]=$Atag; //make old element first element of it's former self
}
if ($E) {
$A[$tag][]=$E; //add new element
}
}
else {
if ($E) {
$A[$tag]=$E; //put it in the array under it's tag name
if ($tag=='ErrorMsg') $error_msg=$E; //make this a global error message, because it can be anywhere in the XML code
}
}
}
return $c;
}
?>
well - please advice - how can i replace the fopen thingy:
since many many servers do not allow the fopen - i have to replace this - Can you assist me here; That would be great:
thanks for the answers in advance!!
bernard_hinault,