You are here: Combining XML, using SimpleXML « PHP Language « IT news, forums, messages
Combining XML, using SimpleXML

Posted by Tips on 12/20/06 00:02

I'm trying to use the Yahoo Search API to get a list of URLs for a site in
the Yahoo index.
I can only get 100 results at a time, but I would like 1000 total (the
maximum), so I want to make 10 queries, each time starting at 100 places
higher. So the first query would get results 1 to 100, the second would
start at 101, and so on.

I'm getting a blank page. Everything works until I try to combine the 10
requests into one XML file, and then I get a blank page. I think it is
because I am trying to make a big XML file out of smaller ones, and
including the entire smaller XML files into the big file.

<?php

// Capture the URL input in the form on the previous page
$url = $_GET['url'];

// makes 10 queries to Yahoo's Search API starting at results 1-100 and
incrementing by 100 on each loop
for($i = 1; $i < 1000; $i += 100) {
$request =
'http://search.yahooapis.com/SiteExplorerService/V1/pageData?appid=useridhere&query='.urlencode($url).'&results=100&start='.$i;

$response = file_get_contents($request);
$xml[$i] = new SimpleXMLElement($response);
}

// combine all arrays of $xml[i] (all 10 requests) into a new string called
$all_xml.
// The problem here is that the new string doesn't just contain <Result>s
from the XML,
// it includes the entire XML file which I think is what is making it fail
foreach ($xml as $value) {
$all_xml .= $value;
}

// Send output
$j = 1;
foreach ($all_xml->Result as $Result) {
echo "#$j: <a href=\"" . $Result->Url ."\">" . $Result->Url . '</a><br
/>';
$j++;
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация