php xml parser -> Table or OPTION from SELECT -
I'm looking for a way to parse something like this:
& Lt; Xml & gt; & Lt; Data & gt; & Lt; Name & gt; Zyx & lt; / Name & gt; & Lt; Price & gt; Xyz & lt; Price & gt; & Lt; / Data & gt; & Lt; Data & gt; & Lt; Name & gt; CBA & lt; / Name & gt; & Lt; Price & gt; ABC & lt; / Pricing & gt; & Lt; / Data & gt; & Lt; / XML & gt;
and change it to:
& lt; SELECT & gt; & Lt; OPTION VALUE = "xyz" & gt; Zyx & lt; / OPTION & gt; & Lt; OPTION VALUE = "abc" & gt; Cba & lt; / OPTION & gt; & Lt; / Select & gt; Use only php so that if a customer is able to look at my source code they will only see the options selected instead of JS parser (which looks confusing and displays the location of the XML file. Is there a way to do this with PHP? And how to use variable input? Select function ($ tid, $ t, $ xml, $ name, $ iid, $ Elname, $ Vname, $ nname) {$ file = file_get_contents ("module / xml / $ xml.xml"); $ Select = New Simple XML ($ F I.e.); Return "& lt; TR & gt; & lt; TD ID = \" $ tid \ "& gt; & amp; nbsp; $ t & lt; / td & gt; & lt; TD ID = \ "$ Tid \" & gt; SELECT NAME = \ "$ name \" & gt; "foreach (choose $ -> $ elname $ option) {return" option " = "$ OPTIONs-> value \"> gt; $ OPTIONs- & gt; name & lt; / OPTION & gt; \ n ";} return}
For example SimpleXMlelement ()
at
$ xml = "& lt; Xml & gt; & Lt; Data & gt; & Lt; Name & gt; Zyx & lt; / Name & gt; & Lt; Price & gt; Xyz & lt; / Pricing & gt; & Lt; / Data & gt; & Lt; Data & gt; & Lt; Name & gt; CBA & lt; / Name & gt; & Lt; Price & gt; ABC & lt; / Pricing & gt; & Lt; / Data & gt; & Lt; / Xml & gt; "; $ Select = New simple assemment ($ xml); echo" & lt; Select ";; foreach ($ select-> data as $ option) {echo" Edit
If you want to load an external .xml file, you can simplexml_load_file ()
-
Select $ = Simple XMLload_file ('XMLFile.exml'); Resonate "select" ;; Foreach ($ select-> data as $ option;) "echo" option value = '$ option- & gt; Value '& Gt; $ Option- & gt; Name & lt; / Option & gt; ";} Echo" & lt; / Select & gt; ";
Comments
Post a Comment