php判断str字符串是否是xml格式数据的方法示例

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php判断str字符串是否是xml格式数据的方法示例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP判断str字符串是否XMl格式数据的方法分享给大家供大家参考,具体如下:

<PRe class="brush:PHp;"> <>PHP //自定义xML验证函数xml_parser() function xml_parser($str){ $xml_parser = xml_parser_create(); if(!xml_parse($xml_parser,$str,true)){ xml_parser_free($xml_parser); return false; }else { return (json_decode(json_encode(simplexml_load_string($str)),true)); } } //应用示例: $xmlstr= Jack Herrington PHP Hacks O'Reilly Jack Herrington Podcasting Hacks O'Reilly XML数据 编程之家 tools.js-code.cc ETO; $jsonstr='{ "tools": [ { "name":"css format","sITe":"http://tools.js-code.cc/code/css" },{ "name":"JSON format","site":"http://tools.js-code.cc/code/json" },{ "name":"pwd check","site":"http://tools.js-code.cc/password/my_password_safe" } ] }'; if(xml_parser($xmlstr)){ echo "\$xmlstr是xml格式数据"; }else{ echo "\$xmlstr不是xml格式数据"; } echo "
"; if(xml_parser($jsonstr)){ echo "\$jsonstr是xml格式数据"; }else{ echo "\$jsonstr不是xml格式数据"; } ?>

脚本宝典总结

以上是脚本宝典为你收集整理的php判断str字符串是否是xml格式数据的方法示例全部内容,希望文章能够帮你解决php判断str字符串是否是xml格式数据的方法示例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。