You are here:  » url variable encoding


url variable encoding

Submitted by filser on Fri, 2010-02-26 10:47 in

I have a page called parsefile.php with the Magic Parse script integrated.
The xml-file to be parsed is passed into the page as an url- variable: example-> http://www.parsefile.php?feed=xxxx

My Magic Parse script in parsefile.php sits waiting to get the passed variable:

$feed = $_GET[feed];
MagicParser_parse($feed,"myRecordHandler","xml|FEED/ENTRY/");

This works fine, except when the variable string is like this one:

http://cat.internetbrokerproject.be/IBPCatalog/Feed/CatalogAtomFeed.svc/DigestedCatalogItems?$filter=SecureGuid%20eq%20'bf2c7acf-594a-43e4-b868-6873bd6b3910'%20and%20(CompanyCode%20eq%20'0097')

When this is interpreted in my parsefile.php page, the variable is transformed into :

http://cat.internetbrokerproject.be/IBPCatalog/Feed/CatalogAtomFeed.svc/DigestedCatalogItems?$filter=SecureGuid eq \'bf2c7acf-594a-43e4-b868-6873bd6b3910\' and (CompanyCode eq \'0097\')

which is not exactly the same, and thus the parsing isn't executed. (when injecting the original url directly in the script, it works)

Obviously, the problem has something to do with the en- or decoding of the url-variable. What I want, is to retrieve the url-variable exactly as it was originally written.

How can this be achieved ?
Thanks for your help and input !

Filip

Submitted by support on Fri, 2010-02-26 12:13

Hello Filip,

It looks like the URLs that are being passed to your script are not being URL encoded in the first instance, so ultimately, it would need to be resolved at that point (i.e. outside your parsefile.php script).

(this is logical - what you get in $_GET["feed"] should be exactly as intended; and if the value was correctly encoded it would be)

It may work if you use urlencode() against $_GET["feed"] as follows:

$feed = urlencode(stripslashes($_GET[feed]));
MagicParser_parse($feed,"myRecordHandler","xml|FEED/ENTRY/");

...but that cannot be guaranteed i'm afraid - ultimately, it should be resolved at the point where the link to parsefile.php is generated...

Once it is resolves at that point; remove the urlencode() call from the above, leaving it as just:

$feed = stripslashes($_GET[feed]);
MagicParser_parse($feed,"myRecordHandler","xml|FEED/ENTRY/");

Hope this helps!
Cheers,
David.