最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php判斷str字符串是否是xml格式數(shù)據(jù)的方法示例

 更新時(shí)間:2017年07月26日 11:02:44   作者:LoveJulin  
這篇文章主要介紹了php判斷str字符串是否是xml格式數(shù)據(jù)的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了php采用自定義函數(shù)針對(duì)xml格式數(shù)據(jù)進(jìn)行驗(yàn)證的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了php判斷str字符串是否是xml格式數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:

<?php
//自定義xml驗(yàn)證函數(shù)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));
    }
}
//應(yīng)用示例:
$xmlstr=<<<ETO
<?xml version="1.0" encoding="UTF-8"?>
<books>
  <book>
    <author>Jack Herrington</author>
    <title>PHP Hacks</title>
    <publisher>O'Reilly</publisher>
  </book>
  <book>
    <author>Jack Herrington</author>
    <title>Podcasting Hacks</title>
    <publisher>O'Reilly</publisher>
  </book>
  <book>
    <author>XML數(shù)據(jù)</author>
    <title>腳本之家</title>
    <publisher>tools.jb51.net</publisher>
  </book>
</books>
ETO;
$jsonstr='{ "tools": [ { "name":"css format" , "site":"http://tools.jb51.net/code/css" }, { "name":"json format" , "site":"http://tools.jb51.net/code/json" }, { "name":"pwd check" , "site":"http://tools.jb51.net/password/my_password_safe" } ] }';
if(xml_parser($xmlstr)){
 echo "\$xmlstr是xml格式數(shù)據(jù)";
}else{
 echo "\$xmlstr不是xml格式數(shù)據(jù)";
}
echo "<br/>";
if(xml_parser($jsonstr)){
 echo "\$jsonstr是xml格式數(shù)據(jù)";
}else{
 echo "\$jsonstr不是xml格式數(shù)據(jù)";
}
?>

運(yùn)行結(jié)果:

$xmlstr是xml格式數(shù)據(jù)
$jsonstr不是xml格式數(shù)據(jù)

PS:這里再為大家提供幾款關(guān)于xml操作的在線工具供大家參考使用:

在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson

在線格式化XML/在線壓縮XML
http://tools.jb51.net/code/xmlformat

XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress

XML代碼在線格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP針對(duì)XML文件操作技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP錯(cuò)誤與異常處理方法總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

浦北县| 元谋县| 英超| 扶绥县| 贵港市| 喀什市| 靖宇县| 太和县| 崇义县| 渝中区| 秀山| 西城区| 咸丰县| 东台市| 鸡东县| 福清市| 广灵县| 湟源县| 兰考县| 柳河县| 米林县| 绵竹市| 佳木斯市| 漠河县| 白山市| 盈江县| 凤山县| 五常市| 庆阳市| 上杭县| 青海省| 哈密市| 山东| 湘潭市| 南郑县| 鹤山市| 读书| 盐城市| 凤山县| 铜川市| 巢湖市|