Új hozzászólás Aktív témák
-
orkester
őstag
válasz
Sk8erPeter #10036 üzenetére
Ez a teljes kód:
<?php
header("Content-Type: text/html; charset=utf-8");
$db_hostname="xyx";
$db_username="xyx";
$db_password="xyx";
if(isset($_GET['feed_url']))
{
$feed_url = $_GET['feed_url'];
}
else
{
die("Need to pass the (consistent) 'feed url'");
}
try
{
$db = mysql_connect($db_hostname,$db_username,$db_password);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
if (!$db)
{
die("Could not connect: " . mysql_error());
}
mysql_select_db("xyx", $db);
echo "Starting to work with feed URL '" . $feed_url . "'";
libxml_use_internal_errors(true);
$RSS_DOC = simpleXML_load_file($feed_url);
if (!$RSS_DOC) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
$rss_title = $RSS_DOC->channel->title;
$rss_link = $RSS_DOC->channel->link;
$rss_category = $RSS_DOC->channel->category;
$rss_description = $RSS_DOC->channel->description;
$rss_date = $RSS_DOC->channel->pubDate;
foreach($RSS_DOC->channel->item as $RSSitem)
{
$item_id = md5($RSSitem->title);
$fetch_date = date("Y-m-j G:i:s");
$item_title = $RSSitem->title;
$item_date = date("Y-m-j G:i:s", strtotime($RSSitem->pubDate));
$item_url = $RSSitem->link;
$item_category = $RSSitem->category;
$item_description = $RSSitem->description;
echo "Processing item '" , $item_id , "' on " , $fetch_date , "<br/>";
echo $item_title, " - ";
echo $item_date, "<br/>";
echo $item_url, "<br/>";
$item_exists_sql = "SELECT item_id FROM rssingest where item_id = '" . $item_id . "'";
$item_exists = mysql_query($item_exists_sql, $db);
if(mysql_num_rows($item_exists)<1)
{
echo "<font color=green>Inserting new item..</font><br/>";
$item_insert_sql = "INSERT INTO rssingest(item_id, feed_url, item_content, item_title, item_date, item_url, item_tema, fetch_date) VALUES ('" . $item_id . "', '" . $feed_url . "', '" . $item_description . "', '" . $item_title . "', '" . $item_date . "', '" . $item_url . "', '" . $item_category . "', '" . $fetch_date . "')";
$insert_item = mysql_query($item_insert_sql, $db);
}
else
{
echo "<font color=blue>Frissítés</font><br/>";
$item_insert_sql = "UPDATE rssingest SET item_tema = ('" . $item_category . "') WHERE item_id = '" . $item_id . "'";
$insert_item = mysql_query($item_insert_sql, $db);
}
echo "<br/>";
}
} catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>És szeretném ha pl. ebből az RSS részletből nem csak az 1. <category> mező kerülne az adatbázisba:
<item>
<link>
http://www.pafi.hu/_pafi/palyazat.nsf/ervdocidweburlap/490FAC2B35FC9E0EC1257A0F0038DC43
</link>
<title>
<![CDATA[
Milyen kérdést intéznék a miniszterekhez, ha képviselő lennék?
]]>
</title>
<description>
<![CDATA[
A kíirók pályázatot hirdetnek gyermekintézmények számára a Gyermekek Világnapja alkalmából.
]]>
</description>
<category>gyermek, ifjúság</category>
<category>közművelődés</category>
<category>művészet</category>
<category>szociális</category>
<pubDate>Sun, 03 Jun 2012 23:51:34</pubDate>
</item>
Új hozzászólás Aktív témák
- Yoga Slim 7 15ILL9 15.3" 3K IPS érintő Ultra 7 256V Arc 140V 16GB 1TB NVMe IR kam gar
- Mint az új! Samsung Galaxy Z Flip5 2 év garanciával
- Iphone 17 Pro Cosmic Orange 256GB/Független
- Acer Nitro ANV16-41 16" FullHD 165Hz - Ryzen 8645HS - 32GB/1TB - RTX 4050
- Asztali PC , R5 5500 , RX 5700 XT , 16GB RAM , 512GB NVME
- Bomba ár! Asus X540YA - AMD A8 I 8GB I 512SSD I Radeon I 15,6" FHD I Cam I W10 I Garancia!
- HP 14 Pavilion FHD IPS i5-1135G7 4.2Ghz 16GB RAM 512GB SSD Intel Iris XE Graphics Win11 Garancia
- Telefon felvásárlás!! Apple Watch SE/Apple Watch SE 2 (2022)
- HIBÁTLAN iPhone 13 mini 256GB Pink -1 ÉV GARANCIA - Kártyafüggetlen, MS3440, 90% Akkumulátor
- Bomba ár! HP Elitebook 840 G1 - i5-4GEN I 8GB I 180GB SSD I 14" HD+ I Cam I W10 I Garancia!
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopműhely Bt.
Város: Budapest