(View Original Web?)

HOBBY > SOURCE CODE

Tutorial PHP Cara mudah parsing data untuk mengambil value file XML


(Page 1 of 1)
 
biasanya kita menggunakan fungsi PHP regular expression ataupun fungsi explode untuk memecah dan mengambil data berdasarkan keyword tertentu, namun dalam hal ini pada PHP versi 5 sudah terdapat fungsi modul untuk mendeklarasikan file XML dalam pengolahan data, oke langsung saja:

Syntax
Code:
class SimpleXMLElement
{
string children(ns,is_prefix)
}

XML File
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

PHP Code
Code:
<?php
$xml 
simplexml_load_file("test.xml");

foreach (
$xml->children() as $child)
  {
  echo 
"Child node: " $child "<br />";
  }
?>

RESULT
Quote
Child node: Tove
Child node: Jani
Child node: Reminder
Child node: Don't forget me this weekend!

 
moga bermanfaat
(Page 1 of 1)

Navigation

Back Sub-Forum