= 0x20) && ($current <= 0xD7FF)) || (($current >= 0xE000) && ($current <= 0xFFFD)) || (($current >= 0x10000) && ($current <= 0x10FFFF))) { $ret .= chr($current); } else { $ret .= " "; } } return $ret; } // get params $method = (isset($_GET['method'])) ? $_GET['method'] : (isset($_POST['method']) ? $_POST['method'] : 'get_rss'); $limit = (isset($_GET['limit'])) ? (int)$_GET['limit'] : (isset($_POST['limit']) ? (int)$_POST['limit'] : 200); // globals $feeds = array( (object) array( 'name' => 'News', 'url' => 'http://dhanara.aishk.edu.hk/feed/' ) ); // output switch ($method) { case 'get_rss': // json data $items = array(); // loop over feeds foreach ($feeds as $feed) { // fetch RSS feed $ch = curl_init($feed->url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $data = curl_exec($ch); curl_close($ch); // remove invalid characters from the xml $data = stripInvalidXml($data); // parse RSS $rss = new SimpleXmlElement($data, LIBXML_NOCDATA); // counter $count = 0; // loop through each item foreach($rss->channel->item as $item) { // increment counter $count++; // generate a integer for a unique id $id = (int) hexdec(substr(sha1($item->title.$item->description),0,8)); $enclosure = ""; if($item->enclosure && $item->enclosure->attributes()) { $enclosure = $item->enclosure->attributes()->url; } $image = preg_match('/]*src="([^"]*)"/', $item->description, $matches); if (isset($matches[1])) { $image = $matches[1]; }elseif (isset($matches[2])) { $image = $matches[2]; }else{ $image = null; } // add items to array used in response $items[] = array( 'id' => $id, 'title' => (string) $item->title, 'feed' => (string) $feed->name, 'url' => (string) $item->link, 'description' => strip_tags($item->description), 'list_order' => $count, 'featured_image' => $image, 'content' => $item->children('content', true)->encoded ); } } // json header header("Content-type: application/json"); // print output echo json_encode( array( 'result' => array_slice($items,0,$limit), 'error' => null, ), JSON_PRETTY_PRINT ); break; }