|  |  | 
          
            | พอดีใช้parse php แล้วต้องการเอาข้อมูลมาลง db อ่ะครับ มันไม่ส่งค่ามาเราต้องใช้การรับค่าแบบไหนอ่ะครับ 
 
 Code (PHP)
 
 <?php
class cfeed
{
  public static function parse($url, $limit=0)
  {
    if(!function_exists('curl_init')) { die('cURL extension needed!'); }
    if(!function_exists('simplexml_load_string')) { die('SimpleXML extension needed!'); }
    $limit = (int)$limit;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $s = curl_exec($ch);
    curl_close($ch);
 
    $feed = simplexml_load_string($s, 'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_COMPACT);
    $items = array();
    $i = 0;
    if(isset($feed->channel))
    {
      $feed = $feed->xpath('//item');
      foreach($feed as $f)
      {
        $i++;
        if($limit>0 && $i>$limit) { break; }
        $item = new stdClass;
        $item->title = trim($f->title);
        $item->description = trim($f->description);
        $item->link = trim($f->link);
        $item->date = trim($f->pubDate);
        $items[] = $item;
      }
    }
    else
    {
      $feed = $feed->entry;
      foreach($feed as $f)
      {
        $i++;
        if($limit>0 && $i>$limit) { break; }
        $item = new stdClass;
        $item->title = trim($f->title);
        $item->description = trim($f->content);
        foreach($f->link as $l)
        {
          if($l['rel'] == 'alternate') 
          {
            $item->link = trim($l['href']);
            break;
          }
        }
        $item->date = trim($f->published);
        $items[] = $item;
      }
    }
    return $items;
  }
}
 
 ในหน้านี้อ่ะครับ ในqueryเราต้องรับค่าแบบไหนอ่าไม่เข้าใจ
 
 Code (PHP)
 
 <?php 
include('include.php');
$objConnect = mysql_connect("localhost","root","localhost") or die("Error Connect to Database");
$objDB = mysql_select_db("localhost");
mysql_query("SET NAMES UTF8");
header('content-type: text/plain');
$URL = 'http://www.nationmultimedia.com/rss/topstories.rss';
$feed = cfeed::parse($URL, 5);
mysql_query("SET NAMES UTF8");
$query = mysql_query("INSERT INTO category VALUES ('','','{$cfeed}','{$row[1]}','{$row[2]}','{$row[3]}','','','','')"); //บรรทัดนี้อ่ะ
echo $query;
print_r($feed);
 
$URL = 'http://www.rssthai.com/rssutf8/sport.xml';
$feed = cfeed::parse($URL, 5); 
print_r($feed);
 
$URL = 'http://i3rssnews.blogspot.com/feeds/posts/default'; 
$feed = cfeed::parse($URL, 5);
print_r($feed);
?>
 
 
 Tag : - - - -
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2009-11-02 09:27:25 | By :
                          isolate | View :
                          965 | Reply :
                          0 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |