You are here:  » Parser works in localhost but does not work on 2 different hosting providers

Support Forum



Parser works in localhost but does not work on 2 different hosting providers

Submitted by tzic on Thu, 2007-12-06 23:23 in

Hello, I just registered to magic parser and I am trying to use the BBC example code with this feed

<?php
  header("Content-Type: text/html;charset=utf-8");
  require("MagicParser.php");
  function myRecordHandler($item)
  {
    print "<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print "<p>".$item["DESCRIPTION"]."</p>";
  }
  print "<h1>BBC News Headlines</h1>";
  $url = "http://www.medicalnewstoday.com/medicalnews.xml";
  MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

It works perfectly in localhost but I get no results on the web. I tried 2 different hosting providers with no luck. One of them is godaddy.com Any thoughts on this issue?

Also is there a way to show only 10 results and not all of them? I read another post about that but I could not figure it out.

thank you in advance

nick

Submitted by support on Fri, 2007-12-07 09:23

Hello Nick,

If it's working locally but not on your servers, it is almost certainly because your servers have url wrappers disabled so they are not permitted to open URL using the fopen() function (which is what Magic Parser uses to open the file or URL). Have a look at the following thread which has links to information on URL wrappers and how to enable them:

http://www.magicparser.com/node/189

(note also the last comment in that thread with an entry to add to .htaccess which may work for you)

With regards to limiting the output to 10 results, all you need to do is setup a global counter, increment it for each record, and then return TRUE from myRecordHandler when it has reached 10. Magic Parser stops parsing if myRecordHandler returns TRUE. For example:

<?php
  header
("Content-Type: text/html;charset=utf-8");
  require(
"MagicParser.php");
  
$counter 0;
  function 
myRecordHandler($item)
  {
    global 
$counter;
    print 
"<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    print 
"<p>".$item["DESCRIPTION"]."</p>";
    
$counter++;
    return (
$counter == 10);
  }
  print 
"<h1>BBC News Headlines</h1>";
  
$url "http://www.medicalnewstoday.com/medicalnews.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

Hope this helps,
Cheers,
David.

Submitted by tzic on Fri, 2007-12-07 11:17

Its the first time I have so immediate and accurate, fast response in a support forum. Problem solved turning register_globals and allow_url_fopen to ON at my php.ini file on the server.

thank you very much David.