Example of how php checks whether the str string is xml-format data, strxml
This example describes how php judges whether the str string is in xml format. We will share this with you for your reference. The details are as follows:
<? Php // custom xml verification function 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); }}// application example: $ 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> <author> XML data </author> <title> helper house </title> <publisher> tools.jb51.net </publisher> </book> </books> ETO; $ jsonstr = '{"tools": [{"name": "css format", "site": "http://tools.j B51.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 is xml format data ";} else {echo "\ $ xmlstr data not in xml format";} echo "<br/>"; if (xml_parser ($ jsonstr )) {echo "\ $ jsonstr is xml format data";} else {echo "\ $ jsonstr is not xml format data" ;}?>
Running result:
$ Xmlstr is data in xml format $ jsonstr is not data in xml format
PS: Here are some online tools for xml operations for your reference:
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
Online formatting XML/online compression XML:
Http://tools.jb51.net/code/xmlformat
XMLOnline compression/formatting tools:
Http://tools.jb51.net/code/xml_format_compress
XMLCode Online formatting and beautification tools:
Http://tools.jb51.net/code/xmlcodeformat