안녕 얘들 아 XML을 구문 분석하고 PHP로 저장하려고 해요? (중간에 있어요). 이미 XML을로드하고 표시 할 데이터 만 표시합니다. 어떻게 할 수 있습니까? 나는 XML을 저장합니까? 어떻게 XML을로드하고 PHP로 저장할 수 있습니까?
이
내 코드입니다 :<?php
$html = "";
$url = "http://www.conciencia.net/rss.aspx";
$xml = simplexml_load_file($url);
$channel_title = $xml->channel->title;
$channel_link = $xml->channel->link;
$managingEditor = $xml->channel->managingEditor;
$channel_description = $xml->channel->description;
$lbd = $xml->channel->lastBuildDate;
$html .= "<br/>$channel_title";
$html .= "<br/>$channel_link";
$html .= "<br/>$managingEditor";
$html .= "<br/>$lbd";
$html .= "<br/>$channel_description<br/>";
for($i = 0; $i < 7; $i++){
$pubDate = $xml->channel->item[$i]->pubDate;
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
$guid = $xml->channel->item[$i]->guid;
$author = $xml->channel->item[$i]->author;
$description = $xml->channel->item[$i]->description;
$url0 = $xml->channel->item[$i]->enclosure->attributes()->url;
for($ii = 0; $ii < 2; $ii++){
$url = $xml->channel->item[$i]->enclosure[$ii]->attributes()->url;
}
$html .= "<br/>$pubDate";
$html .= "<a href='$link'><h3>$title</h3></a>";
$html .= "<br/>$guid";
$html .= "<br/>$author";
$html .= "<br/>$description";
$html .= "<br/>$url0";
$html .= "<br/>$url";
$html .= "<br/>$link<br/>";
}
echo $html;
?>
그 코드 작업 좋은, 난 그냥 표시 할 XML에서 태그를로드 는 내가 그 후하고 싶은 것은 다음과 같습니다의 (a XML을 만드는 것입니다 구조화)하고 데이터를 저장하십시오. 어떻게 할 수 있습니까?
myxml.xml
<channel>
<title>$channel_title</title>
<link>$channel_link</link>
<managingEditor>$managingEditor</managingEditor>
<channel_description>$channel_description</channel_description>
<item>
<title>$title</title>
<guid>$guid</guid>
<author>$author</author>
<description>$description</description>
<enclosure0>$url0</enclosure0>
<enclosure1>$url</enclosure>
</item>
<item>
<title>$title</title>
<guid>$guid</guid>
<author>$author</author>
<description>$description</description>
<enclosure0>$url0</enclosure0>
<enclosure1>$url</enclosure>
</item>
<item>
<title>$title</title>
<guid>$guid</guid>
<author>$author</author>
<description>$description</description>
<enclosure0>$url0</enclosure0>
<enclosure1>$url</enclosure>
</item>
<item>
<title>$title</title>
<guid>$guid</guid>
<author>$author</author>
<description>$description</description>
<enclosure0>$url0</enclosure0>
<enclosure1>$url</enclosure>
</item>
<item>
<title>$title</title>
<guid>$guid</guid>
<author>$author</author>
<description>$description</description>
<enclosure0>$url0</enclosure0>
<enclosure1>$url</enclosure>
</item>
<item>
<title>$title</title>
<guid>$guid</guid>
<author>$author</author>
<description>$description</description>
<enclosure0>$url0</enclosure0>
<enclosure1>$url</enclosure>
</item>
<item>
<title>$title</title>
<guid>$guid</guid>
<author>$author</author>
<description>$description</description>
<enclosure0>$url0</enclosure0>
<enclosure1>$url</enclosure>
</item>
</channel>
변수를 HTML로 이스케이프 처리하려면 'htmlspecialchars()'를 사용해야합니다. –
http://stackoverflow.com/questions/3418376/how-to-save-changed-simplexml-object-back-to-file –
의 가능한 복제물 xml을 작성해야하는 이유는 무엇입니까? 당신은 실제로 아무것도 수정하지 않았습니다. 방금 일부 XML 속성을 가져 와서 HTML로 출력합니다. – r3wt