CiscoTavon
asked on
convert 5.1.2 code php to 5.0.4
I've been doing research on why my code is not working and it seems, and please correct me if I am wrong, it is due to this part
$xml = new SimpleXMLElement($xml_requ est_url, null, true);
it appears SimpleXML is not supported in 5.0.4, needs to 5.1.x, I cannot change the PHP version on the server, is it possible to convert this code so it will work with 5.0.4.
$xml = new SimpleXMLElement($xml_requ
it appears SimpleXML is not supported in 5.0.4, needs to 5.1.x, I cannot change the PHP version on the server, is it possible to convert this code so it will work with 5.0.4.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
</head>
<body>
<form name='frmTest' method='post' action='<?php echo $_SERVER['PHP_SELF'];?>'>
<input type='text' name='txtSearch'/>
<input type='submit' value='Search'/>
</form>
<?php
if (isset($_POST["txtSearch"])) {
$user_name = 'UserName';
$secret_key = 'gfjuhchj';
$search_phrase = $_POST["txtSearch"];
$query_hash = md5($secret_key.$search_phrase);
$xml_request_url = 'http://www.allcdcovers.com/api/search/'.$user_name.'/'.$query_hash.'/'.urlencode($search_phrase);
$xml = new SimpleXMLElement($xml_request_url, null, true);
if (isset($xml->err)) {
echo $xml->err['msg'];
} else {
print "<table>";
foreach ($xml as $title) {
echo "<tr><td><h3>'Title: '</h3>".$title->name."</td></tr><br />";
echo "<tr><h3>'Category: ''</h3>".$title->category.': '.$title->subcategory."<br />";
echo "<a href='Image: '><img src=".$title->image."/></a> <br /> ";
foreach ($title->covers->cover as $cover) {
echo "<h3>'Average rating:''</h3>".$cover->average_rating."<br />";
}
}
}
}
?>
</body>
</html>
If you can get the contents of the page via what rjdown suggested. Try throwing the contents into simplexml like this:
$xml = simplexml_load_string($str ing);
print_r( $xml );
SimpleXML is 5.0+
$xml = simplexml_load_string($str
print_r( $xml );
SimpleXML is 5.0+
Has rjdown's solution worked for you?
Otherwise could you give the full error message you receive?
Otherwise could you give the full error message you receive?
ASKER
rjdown I see the Google page.
the error message is
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__const ruct() expects exactly 1 parameter, 3 given' in /home/07009321/public_html /b1.php:23 Stack trace: #0 /home/07009321/public_html /b1.php(23 ): SimpleXMLElement->__constr uct('http://www.allc...', NULL, true) #1 {main} thrown in /home/07009321/public_html /b1.php on line 23
the error message is
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__const
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One possibility is that you do not have allow_url_fopen set to On. You can change this in your php.ini file. If you have shared hosting, you'll likely need to ask your provider to change it, there is no other way around that as far as I know.
A simple test will show if it is enabled. Create a new file with the following contents:
<?php
$test = file_get_contents("http://www.google.com");
echo $test;
?>
If you see the google homepage, then the problem is not that!