XML [XML] 디비에 저장된 XML 형식의 데이타에서 자료 추출하기
페이지 정보
본문
디비에 저장된 XML 형식의 데이타에서 자료 추출하기 ( XML 파싱 / XML Parsing )
<?php
$Files = '
<Root>
<File Size="310330">
<Ori>IMG1.jpg</Ori>
<Name>11.jpg</Name>
<Url>/Upload/</Url>
<Path>D:\Upload\</Path>
</File>
<File Size="802710">
<Ori>IMG2.png</Ori>
<Name>22.png</Name>
<Url>/Upload/</Url>
<Path>D:\Upload\</Path>
</File>
</Root>
';
$Files2= '<Root><File Size="310330"><Ori>IMG1.jpg</Ori><Name>11.jpg</Name><Url>/Upload/</Url><Path>D:\Upload\</Path></File><File Size="802710"><Ori>IMG2.png</Ori><Name>22.png</Name><Url>/Upload/</Url><Path>D:\Upload\</Path></File></Root>';
$new_xml = "";
if ($Files2) {
$xml = simplexml_load_string($Files2);
foreach($xml->File as $obj){
$new_xml .= '<img src="';
$new_xml .= $obj->Url;
$new_xml .= $obj->Name;
$new_xml .= '" />';
}
}
echo $new_xml;
?>
결과
<img src="/Upload/11.jpg" /><img src="/Upload/22.png" />
참고자료
http://php.net/manual/en/function.xml-parse-into-struct.php
https://sir.kr/qa/216271
<?php
$Files = '
<Root>
<File Size="310330">
<Ori>IMG1.jpg</Ori>
<Name>11.jpg</Name>
<Url>/Upload/</Url>
<Path>D:\Upload\</Path>
</File>
<File Size="802710">
<Ori>IMG2.png</Ori>
<Name>22.png</Name>
<Url>/Upload/</Url>
<Path>D:\Upload\</Path>
</File>
</Root>
';
$Files2= '<Root><File Size="310330"><Ori>IMG1.jpg</Ori><Name>11.jpg</Name><Url>/Upload/</Url><Path>D:\Upload\</Path></File><File Size="802710"><Ori>IMG2.png</Ori><Name>22.png</Name><Url>/Upload/</Url><Path>D:\Upload\</Path></File></Root>';
$new_xml = "";
if ($Files2) {
$xml = simplexml_load_string($Files2);
foreach($xml->File as $obj){
$new_xml .= '<img src="';
$new_xml .= $obj->Url;
$new_xml .= $obj->Name;
$new_xml .= '" />';
}
}
echo $new_xml;
?>
결과
<img src="/Upload/11.jpg" /><img src="/Upload/22.png" />
참고자료
http://php.net/manual/en/function.xml-parse-into-struct.php
https://sir.kr/qa/216271
댓글목록
등록된 댓글이 없습니다.