Page 1 of 1

HELP: loading a url with simplexml that has a string in it

Posted: Sun Jun 06, 2010 11:09 pm
by nzsystem
Hi i am new to php and am trying to write a page that parsing some xml using simplexml and i think i have managed to learn most of it but I am having a problem with loading a url to be parsed that has a variable loaded from a text box.

Here is the code that i thought would work:

Code: Select all

<?php
$moviename = $_POST['moviename'];
$xml = simplexml_load_file("http://api.themoviedb.org/2.1/Movie.search/en/xml/.../%s\n", $moviename);
?>
when i try to load the page once something has been entered in the text box on the other page i get an error, for this example i entered 'Transformers' into the text field and loaded the page and this is the error that i got:

Code: Select all

Warning: simplexml_load_file() expects parameter 2 to be a class name derived from SimpleXMLElement, 'Transformers' given in D:\Apache\htdocs\MovieCatalogue\movieresults.php on line 3
Any help as to what i am doing wrong would be appreciated.

Thanks

Re: HELP: loading a url with simplexml that has a string in

Posted: Mon Jun 07, 2010 1:51 am
by cpetercarter
You have placed a comma between the url and the varaible $moviename. php therefore thinks that $moviename is a second argument for simplexml_load_file(). If you look at the php manual you will see that the optional second argument for simplexml_load_file() has to be the name of a class which extends SimpleXMLElement. Hence the error message.

I don't think that you intended to pass a second argument to simplexml_load_file(). I guess that you simply wanted to append the value in $moviename to the end of the url. php uses a full stop (period), not a comma, to concatenate strings. I also wonder about the "%s\n" bit at the end of the url. Is this really part of the url you want to read?