开发者

How to replace string on array index?

This is my XML file.

  <sekolah>
    <satuan_pendidikan>SMA/MA</satuan_pendidikan>
    <program-keahlian>-</program-keahlian>
    <program-tk />
    <nama-sekolah>SMA Bintang Kejora</nama-sekolah>
    <nss>10101623166</nss>
    <alamat>Jl Kemerdekaan</alamat>
    <kecamatan>Cengkareng</kecamatan>
    <kabupaten-kota>Jakarta</kabupaten-kota>
    <propinsi>Jakarta Barat</propinsi>
    <kodepos>12950</kodepos>
    <telepon>021-56246</telepon>
    <faksimili />
    <email>sma_bintang_kejora@yahoo.com</email>
    <status-sekolah>SWASTA</status-sekolah>
    <nama-yayasan>Bintang Kejora</nama-yayasan>
    <nomor-akte-pendirian-terakhir>92800</nomor-akte-pendirian-terakhir>
    <tahun-berdiri>2001</tahun-berdiri>
    <status-akreditasi />
    <visi>Visi</visi>
    <misi>Visi</misi>
  </sekolah>

This my PHP code.

$string = file_get_contents("sma-bintang-kejora.xml");
$xml = simplexml_load_string($string);
print_r ($xml) ;
echo '<hr />';

echo $xml->sekolah->satuan_pendidikan.'<br />';
echo $xml->sekolah->alamat.'<br />';
echo $xml->sekolah->kecamatan.'<br />';

I have an error when I try to echo $xml->sekolah->program-keahlian.'<br />'; // output w开发者_StackOverflow社区ill be 0.

Can we replace the index array on XML after the string "-"?

$xml = simplexml_load_string($string); 


The dash in your tag means you have to use the {''} syntax:

echo (string)$xml->{'program-keahlian'};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜