最新国产好看的视频,伊人天堂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基本語(yǔ)法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

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

相關(guān)文章

最新評(píng)論

苍山县| 滁州市| 龙岩市| 犍为县| 衡东县| 宣恩县| 外汇| 五莲县| 潜江市| 沁水县| 民县| 淮北市| 杂多县| 茌平县| 太湖县| 沁水县| 永平县| 新密市| 东乌珠穆沁旗| 通山县| 西乌珠穆沁旗| 城市| 台南市| 潮安县| 普陀区| 罗田县| 安图县| 邵东县| 中卫市| 石城县| 峨边| 金乡县| 开鲁县| 宁远县| 临沧市| 廊坊市| 广丰县| 久治县| 江孜县| 鄂托克前旗| 竹溪县|