Xml learning notes
<? Php $ textTpl = '<xml> <Content> <! [CDATA [% s]> </Content> <news> <! [CDATA [% s]> </news> <FuncFlag> <! [CDATA [% s]> </FuncFlag> <body> <! [CDATA [addcon]> </body> </xml> '; // $ xmlobj = SimpleXML () $ postObj = simplexml_load_string ($ textTpl, 'simplexmlelement', LIBXML_NOCDATA ); // load xml and encapsulate xml into an object echo $ postObj-> Content; // obtain the value of the xml Element $ postObj-> body [0]-> addChild ("date ", "2016-01-01"); // Add a subnode foreach ($ postObj-> body-> children () as $ child) {echo "Child node :". $ child; // output the newly added child node} // or use echo $ postObj-> body-> date; to directly output // assign values to xml elements
$ String = "decimal: % s, floating point: % f, string: % s"; $ number = "123"; $ fnumber = "123.123 "; $ str = "qwee1231wqaqe3q"; $ txt = sprintf ($ string, $ number, $ fnumber, $ str); // sprintf dial percentage (%) replace the symbol with the variable % s % f passed as the parameter to be replaced with the variable/* sprintf data format %-return a percent sign % B-Binary Number % the character % d corresponding to the c-ASCII value contains the decimal number of plus and minus signs (negative, 0, positive) % e-use lower-case scientific notation (e.g. 1.2e + 2) % E-use upper-case scientific notation (e.g. 1.2E + 2) % u-decimal number (greater than or equal to 0) % f-floating point number (local) % F-floating point number (non-local) % g-shorter % e and % f % G-shorter % E and % f % o-octal digits % s-string % x-hexadecimal digits (lowercase letters) % X-hexadecimal number (uppercase letter */$ outstr = sprintf ($ textTpl, $ number, $ str, $ fnumber ); // put the variable into xml $ postObj = simplexml_load_string ($ outstr, 'simplexmlelement', LIBXML_NOCDATA); // load xmlecho $ outstr; // output the entire xml file echo $ postObj-> FuncFlag; // obtain the value in xml