You are here:  » how to include magicparser to an xtemplate php page

Support Forum



how to include magicparser to an xtemplate php page

Submitted by atman on Fri, 2008-01-11 06:33 in

hi, i need help with including this

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($item)
  {
    print 
"<a href='".$item["LINK"]."'>".$item["TITLE"]."</a>";
  }
  
$url "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

on a php page using xtemplate.

here is an example of a simple expression.

$box_content = "Hello World, today's date is" . date("F j, Y, g:i a");

some advice that.

"If your PHP has print or echo statements in it, remove them and concatenate them into a variable instead. If you try printing from that file, it won't work as you found for your self."

how can i do it with the magicparser example above?

thanks in advance.

Submitted by support on Fri, 2008-01-11 09:21

Hi,

It sounds like what you need to do is create a global variable called $box_content; and then append all the output to that variable rather than print it directly. Then you can use $box_content within your template file. For example:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($item)
  {
    global 
$box_content;
    
$box_content .= "<a href='".$item["LINK"]."'>".$item["TITLE"]."</a> ";
  }
  
$url "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

Hope this helps,
Cheers,
David.