PHP 어린이 () 함수
예
아이를 찾기 노드 참고 노드 :
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
»인스턴스를 실행
정의 및 사용
아이들 () 지정된 노드의 자식 노드를 찾는 기능을한다.
문법
children( ns,is_prefix );
参数 | 描述 |
---|---|
ns | 可选。规定一个 XML 命名空间。 |
is_prefix | 可选。规定一个布尔值。如果值为 TRUE,则 ns 是前缀。如果值为 FALSE,则 ns 是命名空间 URL。 |
기술 세부 사항
반환 값 : | SimpleXMLElement 오브젝트를 돌려줍니다. |
---|---|
PHP 버전 : | 5.0.1+ |
PHP 업데이트 로그 : | 추가 is_prefix 매개 변수를 설정합니다. |
더 많은 예제
예 1
자식 노드 체 노드 찾기 :
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body><span>Important!</span> Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body><span>Important!</span> Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
»인스턴스를 실행
PHP SimpleXML을 참조 설명서