Here’s that XML file again, but this time with autoArray and autoText turned off:Īs you can see it’s much more verbose and harder to read. Another is to turn autoArray off which converts all tags into arrays, regardless of other child nodes. ![]() But what about a company with only one person? How would the function know what to do? One option is to use the alwaysArray option to provide a list of tag names which should always be considered arrays. In the above example, again, we turn the elements into an array because there are several of them. If this is a problem for you, set autoText to false and text content will always be assigned to a $ key, regardless of other attributes (see example below). ![]() Here is a PHP function to do that very thing.įunction xmlToArray($xml, $options = array()). Since most modern applications and APIs use JSON instead, it’s often necessary to convert XML into JSON. ![]() For whatever reason, somebody once thought it was a good idea and now we’re stuck with it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |