我如何使用 SimpleXML 在 PHP 中回应这一点
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>
好的,我正在学习如何使用 SimpleXML。我正在运行一个脚本来从不同的站点运行类似的 API,但这是不同的。我不确定如何使用 PHP 来回显错误(如果是错误)或字符串(如果成功)。我现在使用的 API 只有 true 或 false,但无论结果如何,它仍然是相同的层次结构。
例如
http://gdataonline.com/qkhash.php?mode=xml&哈希=notanactualhashandwillnotbefound 将找不到该哈希值。 http://gdataonline.com/qkhash.php?mode=xml&hash= 098f6bcd4621d373cade4e832627b4f6 该哈希将返回“test”,
正如您所看到的,层次结构将是相同的,因此易于解析和回显
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&hash=notanactualhashandwillnotbefound
That hash will not be found.
http://gdataonline.com/qkhash.php?mode=xml&hash=098f6bcd4621d373cade4e832627b4f6
That hash will return "test"
As you can see the hierarchy will be the same, and thus easy to parse and echo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我明白你在问什么,但你只需将 URL 加载到 SimpleXml 并通过常规对象表示法访问节点,例如
下面的示例将从 URL 加载 XML 并输出错误(如果存在),如果不存在则输出错误它将输出字符串节点。
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.
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.