Ta ut url fra media:thumbnail i XML filer...

Regulæruttrykk, objektorientering, samt problemstillinger omkring optimalisering og sikkerhet.

Ta ut url fra media:thumbnail i XML filer...

Innlegg sveipno » 25.06.2015 12:14

Noen som kan hjelpe med å tar ut urlen fra media:thumbnail i xml filer?

Bruker denne koden:

Kode: Merk alt

// FEED DATA
$raw_rss1 = 'http://rss.cnn.com/rss/money_topstories.rss';
$rss1 = simplexml_load_file($raw_rss1, null, LIBXML_NOERROR);
if (!$rss1 === false) {
   $oko_bl_feeds1 = array (
   'urlName' => 'CNN Money',
   'url' => 'http://rss.cnn.com/rss/money_topstories.rss',
    'source' => "http://money.cnn.com/",
    'icon' => 'feed_icon_cnn'
);
} else {
$oko_bl_feeds1 = array (
   'urlName' => 'Error in RSS feed',
   'url' => 'http://www.sveip.no/_rss/_error.xml',
    'source' => 'http://www.sveip.no/',
    'icon' => 'feed_icon_sveip',
   );
}

$raw_rss2 = 'XXXXXXXXXXXX';
$rss2 = simplexml_load_file($raw_rss2, null, LIBXML_NOERROR);
if (!$rss2 === false) {
   $oko_bl_feeds2 = array (
   'urlName' => 'XXXXXXXXXXXX',
   'url' => 'XXXXXXXXXXXX',
    'source' => "XXXXXXXXXXXX",
    'icon' => 'feed_icon_dine_XXXXXXXXXXXX'
);
} else {
$oko_bl_feeds2 = array (
   'urlName' => 'Error in RSS feed',
   'url' => 'http://www.sveip.no/_rss/_error.xml',
    'source' => 'http://www.sveip.no/',
    'icon' => 'feed_icon_sveip',
   );
}

$raw_rss3 = 'XXXXXXXXXXXX';
$rss3 = simplexml_load_file($raw_rss3, null, LIBXML_NOERROR);
if (!$rss3 === false) {
   $oko_bl_feeds3 = array (
   'urlName' => 'XXXXXXXXXXXX',
    'url' => 'XXXXXXXXXXXX',
    'source' => "XXXXXXXXXXXX",
    'icon' => 'feed_icon_XXXXXXXXXXXX'
);
} else {
$oko_bl_feeds3 = array (
   'urlName' => 'Error in RSS feed',
   'url' => 'http://www.sveip.no/_rss/_error.xml',
    'source' => 'http://www.sveip.no/',
    'icon' => 'feed_icon_sveip',
   );
}

$oko_bl_feeds = array(
$oko_bl_feeds1,
$oko_bl_feeds2,
$oko_bl_feeds3
);

$feed = file_get_contents($oko_bl_feeds);
$feed = iconv("UTF-8","UTF-8//IGNORE",$feed);
$feed = str_replace(array("&", "&"), array("&", "&"), file_get_contents($feed));
$feed = simplexml_load_string($feed);
$feed = $oko_bl_feeds;

$oko_bl_entries = array();
foreach ($oko_bl_feeds as $oko_bl_feedname => $oko_bl_feed) {
  $oko_bl_xml = simplexml_load_file($oko_bl_feed['url']);
  $oko_bl_tmpentries = $oko_bl_xml->xpath('/rss/channel/item');
  foreach ($oko_bl_tmpentries as &$oko_bl_entry) {
     $oko_bl_dc = $oko_bl_entry->children('http://purl.org/dc/elements/1.1/');
     $oko_bl_entry->feedicon = $oko_bl_feed['icon'];
     $oko_bl_entry->feedtitle = $oko_bl_feedname;
     $oko_bl_entry->feedsource = $oko_bl_feed['source'];
if ($oko_bl_dc->date) {
     $oko_bl_dc_date1 = date("Y.m.d", strtotime($oko_bl_dc->date));
     $oko_bl_dc_date2 = date("H:i", strtotime($oko_bl_dc->date));
     $oko_bl_pubDate = $oko_bl_dc_date1 ." kl.".$oko_bl_dc_date2;
     $oko_bl_entry->pubDate = $oko_bl_pubDate;
}
if (!$oko_bl_dc->date) {
     $oko_bl_pubDate1 = date("Y.m.d", strtotime($oko_bl_entry->pubDate));
     $oko_bl_pubDate2 = date("H:i", strtotime($oko_bl_entry->pubDate));
     $oko_bl_pubDate = $oko_bl_pubDate1 ." kl.".$oko_bl_pubDate2;
     $oko_bl_entry->pubDate = $oko_bl_pubDate;
}
     $oko_bl_entry->img = $oko_bl_entry->enclosure['url'];
     $oko_bl_entries[] = $oko_bl_entry;
  }
}

// SORTING BY PUBDATE
function oko_bl_sort_xml($oko_bl_b, $oko_bl_a) {
  $oko_bl_ret_data = strnatcmp($oko_bl_a->pubDate, $oko_bl_b->pubDate);
  if (!$oko_bl_ret_data)
    $oko_bl_ret_data = strnatcmp($oko_bl_a->title, $oko_bl_b->title);
  return $oko_bl_ret_data;
}

usort($oko_bl_entries, 'oko_bl_sort_xml');





// POSTING 1
echo "<div class='blogpost_col'>";
$oko_bl_entries1 = array_slice($oko_bl_entries, 0, 3);
foreach($oko_bl_entries1 as $oko_bl_item) {
$oko_bl_pubDate = preg_replace("/(\d+)\D+(\d+)\D+(\d+)/","$3.$2.$1",$oko_bl_item->pubDate);
$oko_bl_item->description2 = strip_tags($oko_bl_item->description);
if (strlen($oko_bl_item->description2) > 120) {
$stringCut = substr($oko_bl_item->description2, 0, 120);
$oko_bl_item->description2 = substr($stringCut, 0, strrpos($stringCut, " "))."..."; }
$title = str_replace('- ', Null, $oko_bl_item->title);
echo "
<div class='blogpost_entry'>
<a class='blogpost_img' href='{$oko_bl_item->link}' target='_blank'><img class='blogpost_entry_img_img' src='{$oko_bl_item->img}' alt='{$oko_bl_item->title}'></a>
<a class='blogpost_entry_head' href='{$oko_bl_item->link}' target='_blank'>$title</a>
<div class='blogpost_entry_desc'>{$oko_bl_item->description2}</div>
<div class='blogpost_entry_date'>$oko_bl_pubDate</div>
</div>
";
}
echo "</div>";

echo "<div class='blogpost_col'>";
// POSTING 1
$oko_bl_entries2 = array_slice($oko_bl_entries, 3, 3);
foreach($oko_bl_entries2 as $oko_bl_item) {
$oko_bl_pubDate = preg_replace("/(\d+)\D+(\d+)\D+(\d+)/","$3.$2.$1",$oko_bl_item->pubDate);
$oko_bl_item->description2 = strip_tags($oko_bl_item->description);
if (strlen($oko_bl_item->description2) > 120) {
$stringCut = substr($oko_bl_item->description2, 0, 120);
$oko_bl_item->description2 = substr($stringCut, 0, strrpos($stringCut, " "))."..."; }
$title = str_replace('- ', Null, $oko_bl_item->title);
echo "
<div class='blogpost_entry'>
<a class='blogpost_img' href='{$oko_bl_item->link}' target='_blank'><img class='blogpost_entry_img_img' src='{$oko_bl_item->img}' alt='{$oko_bl_item->title}'></a>
<a class='blogpost_entry_head' href='{$oko_bl_item->link}' target='_blank'>$title</a>
<div class='blogpost_entry_desc'>{$oko_bl_item->description2}</div>
<div class='blogpost_entry_date'>$oko_bl_pubDate</div>
</div>
";
}
echo "</div>";


Brukerens avatar
sveipno
Medlem
 
Innlegg: 109
Registrert: 25.03.2012 11:20
Bosted: Lillesand

Gå til Avansert PHP

Hvem er i forumet

Brukere som leser i dette forumet: Ingen registrerte brukere og 4 gjester