views:

77

answers:

1
Response example for MD5 hash found, for example http://md5.noisette.ch/md5.php?hash=2a0231531bc1a7fc29e2fa8d64352ae9 :

<md5lookup>
  <hash>2a0231531bc1a7fc29e2fa8d64352ae9</hash>
  <string>noisette</string>
</md5lookup>

Response for MD5 hash *not* found, for example http://md5.noisette.ch/md5.php?hash=11111111111111111111111111111111 :

<md5lookup>
  <error>
    No value in MD5 database for this hash.
  </error>
</md5lookup>

Response for MD5 hash *not* found, for example http://md5.noisette.ch/md5.php?hash=1 :

<md5lookup>
  <error>
    The string provided is not a true MD5 hash. Please try again.
  </error>
</md5lookup>

Okay I'm just learning how to use SimpleXML. I'm running a script to run similar API's from different sites, but this is different. I'm not sure how I would use PHP to echo the error if it were an error or the string if it were a success. The API's I'm using now have just have true or false but its still the same hierarchy no matter the result.

For example

http://gdataonline.com/qkhash.php?mode=xml&amp;hash=notanactualhashandwillnotbefound That hash will not be found. http://gdataonline.com/qkhash.php?mode=xml&amp;hash=098f6bcd4621d373cade4e832627b4f6 That hash will return "test"

As you can see the hierarchy will be the same, and thus easy to parse and echo

+1  A: 

I'm not sure I understand what you are asking, but you simply load the URL to SimpleXml and access the nodes by regular object notation, e.g.

$parentNode->childNode

The example below will load the XML from the URL and output the error if it exists and if not it will output the string node.

$baseUrl = 'http://md5.noisette.ch/md5.php?hash=';
$hashes  =  array('2a0231531bc1a7fc29e2fa8d64352ae9',
                  '11111111111111111111111111111111',
                  'not a hash');

foreach($hashes as $hash) {

    // load the XML from the URL
    $dom = simplexml_load_file($baseUrl . $hash);

    if($dom->error) {
        echo $dom->error;
    } else {
        echo $hash, ' : ', $dom->string;
    }

    echo PHP_EOL; // linebreak
}
Gordon
Oh right, I didn't think of that, not sure why. Thanks for the help, Gordon. :)
Rob