— Devrim's Tech Stuff

PHP: XML to Array / Object conversion in one line..

This is the first code snippet that I’d like to share with you.

<?php $object = json_decode(json_encode(simplexml_load_string($xml))); ?>

This will give you a wonderful stdClass object, which you can then turn into an array… Neat isn’t it?

It’s just that I see people writing hundreds lines of code for this…

  • Share/Bookmark
3 comments
  1. imitrex says: December 2, 200911:19 am

    nice

  2. flomax says: December 14, 20097:57 pm

    +1K

  3. jB says: June 1, 20102:52 am

    Sweet :D

Submit comment

Get Adobe Flash playerPlugin by wpburn.com wordpress themes