We help IT Professionals succeed at work.
Get Started

convert 5.1.2 code  php to 5.0.4

CiscoTavon asked
Last Modified: 2013-12-13
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_request_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.
<!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">

        <form name='frmTest' method='post' action='<?php echo $_SERVER['PHP_SELF'];?>'>
              <input type='text' name='txtSearch'/>
              <input type='submit' value='Search'/>
      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 />";

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE