<?php
$url = 'https://liputan24.net/?s=banjarbaru&feed=rss2';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$res = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo 'HTTP: ' . $http . PHP_EOL;
echo 'Length: ' . strlen($res) . PHP_EOL;
if (strlen($res) > 0) {
    echo 'Preview: ' . substr($res, 0, 100) . PHP_EOL;
    // Clean XML test
    $rss_content = preg_replace('/xmlns[^=]*="[^"]*"/i', '', $res);
    $rss = @simplexml_load_string($rss_content, 'SimpleXMLElement', LIBXML_NOCDATA);
    if ($rss && isset($rss->channel->item)) {
        echo 'Items found: ' . count($rss->channel->item) . PHP_EOL;
    } else {
        echo 'Failed to parse XML or no items found.' . PHP_EOL;
    }
} else {
    echo 'cURL error: ' . curl_error($ch) . PHP_EOL;
}
