本文實例講述了php中simplexml_load_file函數用法。分享給大家供大家參考。具體用法分析如下:在php中simplexml_load_file() 函數把 XML 文檔載入對象中之后我們就可以利用由此函數返回的對象進行相關的操作了,下面我們看幾個測試實例.例子,XML文件代碼如下: 復制代碼 代碼如下: xml version="1.0" encoding="ISO-8859-1" note to George /to from John /from heading Reminder /heading body Don't forget the meeting! /body /note PHP 代碼如下: 復制代碼 代碼如下: php if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); var_dump($xml); } else { exit('Error.'); }
假如有一個“iciba.xml”文件,其內容如下: 復制代碼 代碼如下: xml version="1.0" encoding="UTF-8" dict num="219" id="219" name="219" key 天空 /key pos /pos acceptation Array;Array; /acceptation sent orig The church tower stood against the sky like a finger pointing towards heaven. /orig trans 教堂的尖塔在天空的映襯下宛如指向天空的手指。 /trans /sent sent orig A balloon floated across the sky. /orig trans 氣球飄過天空。 /trans /sent sent orig A bolt of lightning lit up the sky. /orig trans (一道)閃電照亮了天空。 /trans /sent sent orig A bright moving object appeared in the sky at sunset. /orig trans 日落西山時,天空出現了一個移動的發亮物體。 /trans /sent sent orig A bright rainbow arched above. /orig trans 一彎明亮的彩虹懸掛在天空。 /trans /sent /dict 在PHP語言中我們可以用以下方法取得我們想要的值: 復制代碼 代碼如下: php $xmldata = simplexml_load_file("iciba.xml");