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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nzsystem
Forum Newbie
Posts: 6
Joined: Fri Jun 04, 2010 4:21 am

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

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

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

Post 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?
Post Reply