Last active
January 11, 2016 08:28
-
-
Save fajarlabs/8929916 to your computer and use it in GitHub Desktop.
Mengurutkan Tanggal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function listen_update_via_rss(){ | |
// Listen Update Via Capture XML with Curl | |
function generate_rss_url($site='',$url_feed=''){ | |
$data = curl_init(); // setting CURL | |
curl_setopt($data, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($data, CURLOPT_URL, $url_feed); // menjalankan CURL untuk membaca isi file | |
$hasil = curl_exec($data); | |
curl_close($data); | |
$kodeHTML = $hasil; | |
$pecah = explode('<pubDate>', $kodeHTML); | |
$pecahLagi = explode('</pubDate>', $pecah[1]); | |
$pecah_title = explode('<title>', $kodeHTML); | |
$pecah_title_lagi= explode('</title>', $pecah_title[2]); | |
$title = $pecah_title_lagi[0]; | |
$jam = substr($pecahLagi[0],17,8); | |
$tanggal = substr($pecahLagi[0],5,11); | |
$data_array[] = trim($tanggal).' '.trim($jam); | |
$data_array[] = trim($title); | |
$data_array[] = trim($site); | |
return $data_array; | |
} | |
$q = $this->db->query("SELECT url,url_rss FROM tbl_web"); | |
foreach($q->result() as $row){ | |
if ( $row->url_rss == '' || $row->url_rss == ' ' || $row->url_rss == NULL ) { | |
continue; | |
}else{ | |
//$array_rss_data = array(); | |
$array_rss_data[] = generate_rss_url($row->url,$row->url_rss); | |
} | |
} | |
function date_compare($a, $b){ | |
$t1 = strtotime($a[0]); | |
$t2 = strtotime($b[0]); | |
return $t1 - $t2; | |
} | |
usort($array_rss_data, 'date_compare'); | |
$array_rss_data = array_reverse($array_rss_data); // Membalik array agar Desc | |
echo "<pre>"; | |
echo print_r($array_rss_data); | |
echo "</pre>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment