<?php require( 'Snoopy.class.php' ); // Snoopy require( 'simple_html_dom.php' ); // PHP Simple HTML DOM Parser define( 'ONAIR_URL', 'https://xetown.com/board' ); define( 'RSS_LINK', 'https://xetown.com/board' ); define( 'SITE_TITLE', 'XETOWN - 자유광장' ); define( 'ENCODING', 'UTF-8' ): define( 'LANGUAGE', 'ko' ); $lastpost = 0; $posts = array(); $snoopy = new Snoopy; $snoopy->read_timeout = 5; $snoopy->timed_out = true; $snoopy->fetch( ONAIR_URL ); $response = $snoopy->results; $http_code = $snoopy->response_code; unset($snoopy); if ( strpos($http_code, '200') === FALSE ? ) die(); $html_txt = mb_convert_encoding( $response, ENCODING, 'SJIS-WIN, SJIS, EUCJP-WIN, EUCJP, JIS' ); $dom = str_get_html($html_txt); if ($dom !== FALSE) { $elements = (array) $dom->find('tr[class="bg2"]'); $item_count = 0; foreach ($elements as $element) { $post = array( 'title' => $title , 'permalink' => $url , 'postdate' => $postdate , 'description' => $description , 'tags' => $tags ); if ( array_search( $post, $posts ) === FALSE ) $posts[] = $post; } unset($element); unset($elements); } unset($dom); header('Last-Modified: '.gmdate('D, d M Y H:i:s', $lastpost).' GMT'); header('Content-Type: text/xml; charset=' . ENCODING, true); echo '<?xml version="1.0" encoding="' . ENCODING . '"?' .">\n"; ?> <rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" version="2.0"> <channel> <title><?php echo SITE_TITLE; ?></title> <link><?php echo RSS_LINK; ?></link> <description><?php echo SITE_TITLE; ?></description> <pubDate><?php echo date('D, d M Y H:i:s +0900', $lastpost); ?></pubDate> <language><?php echo LANGUAGE; ?></language> <?php foreach ( $posts as $post ) { ?> <item> <title><?php echo $post['title']; ?></title> <link><?php echo $post['permalink']; ?></link> <pubDate><?php echo date('D, d M Y H:i:s +0900', $post['postdate']); ?></pubDate> <guid><?php echo $post['permalink']; ?></guid> <description><![CDATA[<?php echo $post['description']; ?>]]></description> <?php foreach ((array) $post['tags'] as $tag) { ?> <category><![CDATA[<?php echo $tag; ?>]]></category> <?php } ?> </item> <?php } ?> </channel> </rss>
소스가 작동을 안합니다. 어디서 잘못되었는지 모르겠네요 .....
1. 작동을 안한다면 에러메시지를 확인!! (그냥 die하지 말고 무의미한 메시지 한 줄이라도 출력하도록 해보세요.)
2. 예제에 사용하신 XE타운은 원래부터 UTF-8입니다. 29줄은 일본에서나 통할 것 같네요. 지워보세요.