You are here:  » Passing an additional variable through magic parser


Passing an additional variable through magic parser

Submitted by ksaynor on Fri, 2006-11-24 18:09 in

Hi,

I was wondering whether anyone has managed to pass an additional variable through magic parser?

Bascially I want to do something like this:
MagicParser_parse($url,'myRecordHandler($brandID)',"xml|PRODUCTS/PRODUCT/");

And have it be passed through to my record handler untouched. Any ideas?

I need to do this because a product feed I'm working with doesn't include a brand ID and I need to be able to reliably distinguish between brands.

Cheers,
Karl

Submitted by support on Fri, 2006-11-24 19:17

Hello Karl,

As there is nothing else that can alter $brandID the thing to do is simply to make it a global variable, for example:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    global 
$brandID;
    
// ...use $record and $brandID here...
  
}
  
MagicParser_parse($url,'myRecordHandler',"xml|PRODUCTS/PRODUCT/");
  
$brandID 1234;
?>

Hope this helps,
Cheers,
David.

Submitted by ksaynor on Mon, 2006-11-27 19:40

David,

Of course! Am just dusting off my php skills after a bit of an interval... forgot about global variables! Thanks.

Karl