$fileContents = trim (str_replace ( '"', "'", $fileContents )) $simpleXml = simplexml_load_string ( $fileContents ) Then we call the _simplexml\_load\_string()_ function. Next I replace double quotes with single quotes and trim leadign and trailing spaces, this helps to ensure the simple XML function can parse the XML appropriately. $fileContents = file_get_contents ( $url ) $fileContents = str_replace (array( "\n", "\r", "\t" ), '', $fileContents ) We remove the newlines, returns and tabs. Thankfully, PHP has built in functionality to handle precisely this task.įirst we need to get contents of the XML file, we need to use _file\_get\_contents()_ and pass it the URL to the XML file. I recently needed to convert XML to JSON in PHP. So to get back into the swing of things I am going to KISS this post. Hello all, it’s been a while since I have blogged anything, been extremely busy with personal events in my life. Simple XML to JSON with PHP 21 October, 2011.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |