ÃÑ ÆäÀÌÁö ¼ö : 3224
![]()
|
Facebook Joinc ±×·ì
Joinc QA »çÀÌÆ®
![]()
Tweet
joinc´Â Firefox¿Í chrome¿¡¼ Å×½ºÆ® Çß½À´Ï´Ù. IE¿¡¼´Â Å×À̺íÀÌ ±úÁö°Å³ª À̹ÌÁö°¡ º¸ÀÌÁö ¾ÊÀ» ¼ö ÀÖ½À´Ï´Ù. ƯÈ÷ ±¸±Û DocsÀ̹ÌÁöÀÇ °æ¿ì ¿¢¹Úó¸®µÉ ¼ö ÀÖ½À´Ï´Ù. php xml ÆÄ¼±â
php¸¦ ÀÌ¿ëÇØ¼ °£´ÜÇÑ xml ÆÄ¼±â¸¦ ¸¸µé¾î ºÃ½À´Ï´Ù. °³ÀÎÀûÀ¸·Î joinc¿¡¼ °£´ÜÈ÷ »ç¿ëÇÒ RSS¸®´õ±â Á¦ÀÛÀ» À§ÇÑ º£À̽º Ŭ·¡½º ¿ëµµ·Î »ç¿ëÇÒ »ý°¢ÀÔ´Ï´Ù.
ÄÚµå´Â Á¤ÀçµÇÁö ¾Ê¾ÒÀ¸¸ç, ÃæºÐÈ÷ ÁöÀúºÐÇÕ´Ï´Ù. ¿¡·¯Ã³¸®µµ ¾ÈÇß°í¿ä. ¿©ÇÏÆ°Áö°£¿¡ ÀÛµ¿µÇ³×? ÇÏ´Â °Í¿¡ ÁßÁ¡À» µÐ°Å¶ó¼ ¸»ÀÌÁÒ. ±ò²ûÇÏ°Ô ÇÏ´Â°Ç ³ªÁßÀÏ·Î ÇÒ »ý°¢ÀÔ´Ï´Ù. phpÀÇ xmlÁ¶ÀÛÀº expat ¶óÀ̺귯¸®¸¦ ÀÌ¿ëÇÕ´Ï´Ù. libexpat°¡ ¼³Ä¡µÇ¾î ÀÖ´ÂÁö ¹Ì¸® È®ÀÎÇØºÁ¾ß °ÚÁÒ ? ¸¸¾à C¿¡¼ expat¶óÀ̺귯¸®¸¦ ÀÌ¿ëÇÑ ÇÁ·Î±×·¡¹ÖÀ» ÇØº¸¾Ò´Ù¸é, °ÅÀÇ µ¿ÀÏÇÑ ¹æ¹ýÀ¸·Î »ç¿ëÇÒ ¼ö ÀÖÀ»°Ì´Ï´Ù. ÇÔ¼ö¸íµéµµ °ÅÀÇ µ¿ÀÏÇϰí ÇÏ´ÂÀϵµ ºñ½ÁÇÕ´Ï´Ù. <?php
class XmlParser
{
public $parser;
public $depth=0;
public $termStack;
public $nodeData;
public $fullParseData;
public $prevdepth;
public $uri;
public $last_node;
public $inside_data;
function XmlParser($uri)
{
$this->setURI($uri);
$this->run();
}
function run()
{
$this->termStack = array();
$this->xmlInit();
$this->parsing();
}
function setURI($uri)
{
$this->uri = $uri;
}
function xmlInit()
{
$this->parser = xml_parser_create();
if(!$this->parser) echo "Parser Error<br>";
if(!xml_set_object($this->parser, $this)) echo "xml set object error<br>";
if(!xml_set_element_handler($this->parser, "tag_open", "tag_close")) echo "handler set error<br>";
if(!xml_set_character_data_handler($this->parser, "cdata")) echo "cdata handler error<br>";
}
function cdata($parser, $cdata)
{
if($this->depth > $this->prevdepth)
{
if($this->inside_data)
$this->nodeData[$this->nodeName()] .= $cdata;
else
$this->nodeData[$this->nodeName()] = $cdata;
$this->last_node = $this->nodeName();
}
$this->inside_data=true;
}
function getData($node=null)
{
if($node == null)
{
return $this->fullParseData;
}
return $this->fullParseData[$node];
}
function parsing()
{
$fp = fopen($this->uri, "r");
if(!$fp)
{
return 0;
}
while($data = fread($fp, 9182))
{
$this->parse($data);
}
fclose($fp);
return 1;
}
function parse($data)
{
if(!xml_parse($this->parser, $data)) echo xml_error_string(xml_get_error_code($this->parser));
}
function getpNode($depth=0)
{
if($depth != 0)
{
$node=count($this->termStack) + $depth;
$stack = array_slice($this->termStack, 0, $node);
}
else
{
$stack = $this->termStack;
}
return join("/",$stack);
}
function pushStack($name)
{
array_push($this->termStack, $name);
}
function getStackSize()
{
return count($this->termStack);
}
function tag_open($parser, $tag, $attributes)
{
$this->pushStack($tag);
if($this->depth > $this->prevdepth)
{
if(count($this->nodeData))
{
$last_node = $this->getpNode(-2);
$this->fullParseData[$last_node] = $this->nodeData;
}
$this->nodeData=array();
$this->prevdepth = $this->depth;
}
$this->depth++;
$this->inside_data=false;
}
function tag_close($parser, $tag)
{
$count = count($this->nodeData);
if($count == 0)
array_pop($this->termStack);
$this->depth--;
if($this->depth < $this->prevdepth)
{
if(count($this->nodeData) > 1)
$this->fullParseData[$this->getpNode()][] = $this->nodeData;
else
$this->fullParseData[$this->getpNode()] = $this->nodeData;
$this->nodeData=array();
}
else
{
$this->prevdepth = $this->depth;
}
if($count != 0)
array_pop($this->termStack);
$this->inside_data=false;
}
function nodeName()
{
return $this->termStack[$this->depth-1];
}
}
// yundream ºí·Î±×ÀÇ RSS¸¦ ÀÌ¿ëÇØ¼ Å×½ºÆ®Çغ¸¾Ò´Ù.
$parser = new XmlParser('http://teamblog.joinc.co.kr/yundream/rss');
$items = $parser->getData('RSS/CHANNEL/ITEM');
print_r($items);
foreach($items as $item)
{
echo $item['AUTHOR'],"<br>";
echo $item['TITLE'],"<br>";
}
?>
»ç¿ë¹æ¹ý
´ÙÀ½Àº »ç¿ë¹æ¹ýÀÔ´Ï´Ù. $parser = new XmlParser('http://teamblog.joinc.co.kr/yundream/rss');
$data = $parser->getData();
getData() ¸Þ¼µå¸¦ ÀÌ¿ëÇØ¼ ÇÊ¿äÇÑ ³ëµåÀÇ Á¤º¸¸¦ °¡Á®¿Ã ¼ö ÀÖ½À´Ï´Ù. ³ëµåÀÇ Ç¥ÇöÀº µð·ºÅ丮 ¹æ½ÄÀ» ÀÌ¿ëÇϰí ÀÖ½À´Ï´Ù. ITEM Á¤º¸¸¦ °¡Á®¿À±æ ¿øÇÑ´Ù¸é RSS/CHANNEL/ITEMÇÏ´Â ½ÄÀÌ µË´Ï´Ù. À§ÀÇ ¿¹Á¦¿¡¼´Â RSS¸¦ ÆÄ½ÌÇϰí ÀÖ½À´Ï´Ù. °¢ NODEÀÇ Á¤º¸´Â ´ÙÀ½°ú °°ÀÌ ¾ò¾î¿Ã ¼ö ÀÖ°Ú½À´Ï´Ù. $channel = $parser->getData('RSS/CHANNEL');
echo $channel['TITLE'];
echo $channel['LINK'];
echo $channel['PUBDATE'];
´ÙÀ½Àº ITEMÀ» ¾ò¾î¿À´Â ¿¹ÀÔ´Ï´Ù.
$items = $parser->getData('RSS/CHANNEL/ITEM');
foreach($items as $item)
{
echo $item['AUTHOR'],"<br>";
echo $item['TITLE'],"<br>";
}
±×·°Àú·° ¾ò¾î¿À³×¿ä !!??ÇØ¾ßÇÒ °Í
|
|
|
EmailÀ» ±âÀÔÇϸé, ´ñ±ÛÀÌ ¸ÞÀÏ·Î Àü´ÞµË´Ï´Ù. |
|