PHP __construct() 함수
예시
문자열에서 SimpleXMLElement 개체를 만듭니다.
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
echo $xml->asXML();
?>
정의 및 사용
__construct() 함수는 새 SimpleXMLElement 객체를 만듭니다.
통사론
SimpleXMLElement::__construct(data, options, data_is_url, ns, is_prefix)
매개변수 값
Parameter | Description |
---|---|
data | Required. Specifies A well-formed XML string or the path or URL to an XML document if data_is_url is TRUE |
options | Optional. Specifies additional Libxml parameters. Is set by specifying the option and 1 or 0 (TRUE or FALSE, e.g. LIBXML_NOBLANKS(1)) Possible values:
|
data_is_url | Optional. TRUE specifies that data is a path/URL to an XML document instead of string data. Default is FALSE |
ns | Optional. Specifies a namespace prefix or URI |
is_prefix | Optional. Specifies a Boolean value. TRUE if ns is a prefix. FALSE if ns is a URI. Default is FALSE |
기술적 세부 사항
반환 값: | 데이터 를 나타내는 SimpleXMLElement 객체를 반환합니다. |
---|---|
PHP 버전: | 5.0+ |
PHP 변경 로그: | PHP 5.2.0: 선택적 ns 및 is_prefix 매개변수를 추가했습니다. PHP 5.1.2: 선택적 옵션 과 data_is_url 매개변수를 추가했습니다. |
더 많은 예
다음 XML 파일 " note.xml " 이 있다고 가정합니다 .
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
예시
URL에서 SimpleXMLElement 개체를 만듭니다.
<?php
$xml=new SimpleXMLElement("note.xml", 0, TRUE);
echo $xml->asXML();
?>
❮ PHP SimpleXML 참조