PHP 手冊
上一頁 |  | 下一頁

# simplexml_load_string

(PHP 5)

simplexml_load_string -- Interprets a string of XML into an object.

## Description

object SimpleXMLElement simplexml_load_string ( string data)

This function will take the well-formed xml string data and return an object with properties containing the data held within the xml document. If any errors occur, it returns `FALSE`.

示範 1.Interpret an XML string

`<?php $string = <<<XML <?xml version='1.0'?> <document> <title>Forty What?</title> <from>Joe</from> <to>Jane</to> <body> I know that's the answer -- but what's the question? </body> </document> XML; $xml = simplexml_load_string($string); var_dump($xml); ?>`

This script will display:

    SimpleXMLElement Object
    (
      [title] => Forty What?
      [from] => Joe
      [to] => Jane
      [body] =>
       I know that's the answer -- but what's the question?
    )

At this point, you can go about using $xml->body and such.

See also: simplexml_load_file().

上一頁 | 最開頭 | 下一頁
simplexml_load_file | 上一層 | SOAP Functions