0

i have the following sub piece of code related to my given warning .

$xml[0]="http://www.kat.ph/search/".$_POST['search']."/?rss=1"; //http://www.kat.ph
$xml[1]="http://isohunt.com/js/rss/".$_POST['search']."?iht="; //http://isohunt.com
$xml[2]="http://btjunkie.org/rss.xml?query=".$_POST['search']."&q=".$_POST['search']."&o=52";//http://btjunkie.org          
$xml[3]="http://www.torrentreactor.net/rss.php?search=".$_POST['search'].""; //http://www.torrentreactor.net

 $xmlDoc = new DOMDocument();

for($site_count=0;$site_count<=3;$site_count++)   //LOoP for moving arround all four site

{ 
   $xmlDoc->load($xml[$site_count]);

Problem with code is that some times it loads the link $xml[0] successfully ,but some time it does not load the $xml[0] file . and give the following warnings.

WARNING:

Warning: DOMDocument::load() [domdocument.load]: parsing XML declaration: '?>' expected in http://www.kat.ph/search/kung%20fu%20panda/?rss=1, line: 1 in C:\wamp\www\offlimits\search_data.php on line 40

Warning: DOMDocument::load() [domdocument.load]: Start tag expected, '<' not found in http://www.kat.ph/search/kung%20fu%20panda/?rss=1, line: 1 in C:\wamp\www\offlimits\search_data.php on line 40

Any help of an intelligent would be appreciated :)

Community
  • 1
  • 1

1 Answers1

0

Have you verified that those URLs are actually working and returning valid XML documents? Your code, while syntactically fine, could use some more error handling.

Especially in the construction of those query strings - you SHOULD urlencode() each $_POST insertion so the resulting URL is valid - right now If someone searches for (say) alpha & beta, the resulting urls will look like

 http://example.com?something=alpha & beta

which both contains spaces (not too good), and will only search for the world "alpha", as the " & beta" portion will be treated as some OTHER query parameter.

Marc B
  • 356,200
  • 43
  • 426
  • 500