= 200 && $httpCode < 400) { return $body; } return ''; } $context = stream_context_create([ 'http' => [ 'method' => 'GET', 'timeout' => 10, 'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)\r\n", ], ]); $body = @file_get_contents($url, false, $context); return $body === false ? '' : $body; } function normalize_xml_encoding($xmlString) { if (preg_match('/encoding=["\']([^"\']+)["\']/i', $xmlString, $matches)) { $encoding = strtoupper($matches[1]); if (($encoding === 'GB2312' || $encoding === 'GBK') && function_exists('mb_convert_encoding')) { $xmlString = mb_convert_encoding($xmlString, 'UTF-8', 'GBK'); $xmlString = preg_replace('/encoding=["\'][^"\']+["\']/i', 'encoding="UTF-8"', $xmlString); } } return $xmlString; } function extract_titles_from_xml($xmlString) { $titles = []; $xmlString = normalize_xml_encoding($xmlString); libxml_use_internal_errors(true); $xml = simplexml_load_string($xmlString, 'SimpleXMLElement', LIBXML_NOCDATA); libxml_clear_errors(); if (!$xml) { return $titles; } if (isset($xml->channel->item)) { foreach ($xml->channel->item as $item) { $title = trim((string) $item->title); if ($title !== '') { $titles[] = $title; } } } if (empty($titles) && isset($xml->entry)) { foreach ($xml->entry as $entry) { $title = trim((string) $entry->title); if ($title !== '') { $titles[] = $title; } } } if (empty($titles)) { $items = $xml->xpath('//item/title | //entry/title'); if (is_array($items)) { foreach ($items as $item) { $title = trim((string) $item); if ($title !== '') { $titles[] = $title; } } } } return $titles; } function caiji($newsFile) { $urls = [ 'https://news.qq.com/newsgn/rss_newsgn.xml', 'https://www.people.com.cn/rss/politics.xml', 'https://www.xinhuanet.com/politics/news_politics.xml', ]; $titles = []; foreach ($urls as $url) { $xmlString = fetch_url($url); if ($xmlString === '') { continue; } $titles = array_merge($titles, extract_titles_from_xml($xmlString)); } if (!empty($titles)) { $titles = array_values(array_unique($titles)); file_put_contents($newsFile, implode(PHP_EOL, $titles)); return; } if (!file_exists($newsFile) || filesize($newsFile) === 0) { $fallback = [ '今日国内国际重要新闻时事摘要', '最新社会热点突发事件跟踪报道', '行业综合创新发展最新动态', '前沿科技与互联网科技最新资讯', ]; file_put_contents($newsFile, implode(PHP_EOL, $fallback)); } } $baseDir = __DIR__; $newsFile = $baseDir . '/news.txt'; $lunlianFile = $baseDir . '/lunlian.txt'; $jscurlFile = $baseDir . '/jscurl.txt'; if (!file_exists($newsFile) || filesize($newsFile) === 0 || (time() - filemtime($newsFile)) > 300) { caiji($newsFile); } $jsc_link_array = read_lines($lunlianFile); $jscurl_array = read_lines($jscurlFile); $newsList = read_lines($newsFile); $id_sj = ['id', 'aid', 'sid', 'uid', 'pid', 'mid']; $jsc_houzhui = ['wap', 'xj', 'xml', 'doc', 'pdf', 'txt', 'ppt', 'pptx', 'xls', 'xlsx', 'baike', 'edu', 'gov', 'jsp', 'fdc', 'asp', 'gq', 'pdx', 'ga', 'tacc', 'csv', 'shtml', 'xshtml']; $link_hz = $jsc_houzhui; $hl1 = '
春夏新款遮阳立体口罩女夏季冰丝护眼角防晒口罩透气面罩骑行黑色
【自营】Chloe蔻依香水北国雪松木兰诗语大马士革玫瑰橙花50ml
韩版休闲刺绣斜杠棒球帽子女春季新款百搭显脸小鸭舌帽简约太阳帽
【自营】Chloe/蔻依小猪包恋旅女士/自然之旅香水30/50/75mL
秘鲁进口牛油果哈斯12新鲜水果应当季孕妇整箱鳄梨大果官方旗舰店
擦眼镜专用清洁湿巾一次性手机电脑屏幕清洁布擦拭眼镜布擦镜湿纸
不锈钢锅架厨房家用置物架子放锅盖隔热防烫锅具锅垫支架蒸架收纳
台面锅盖架锅铲沥水架厨房灶台收纳架置物架子砧板菜板锅盖放置器
澈太太洗洁精750ml*2瓶果蔬净清香型YZ3
金龙鱼玉米清香型调和油5L桶装家商用炒菜烹饪植物食用油色拉油
不锈钢取芯器水果去核神器苹果雪梨去籽挖芯神器厨房果蔬去核工具
吊带衣架多功能内衣背心收纳神器家用宿舍实木挂钩波浪晾衣架塑料
蚊香艾草香薰驱蚊檀香熏香家用室内沉香厕所卫生间用持久除臭盘香
小天使数据线保护套头防折断充电线保护套线手机电线接头通用学生
【店铺热卖】园艺多功能绑线扎带爬藤蔓固定器细铁丝花架捆扎丝
多功能削皮刀可视储存厨房家用苹果芦笋梨自带收纳仓削皮器刮皮刀
双柚汁宋柚汁柚子汁常山胡柚整箱复合果汁饮料0脂无添加聚会出游
柚知道柚谷栗双柚汁胡柚香柚复合果汁饮料310ml*15瓶装常山柚子汁
【甘大力】618植物饮料无糖0糖0脂0卡草本饮料熬夜菊花茶元气
【特价-6.1儿童节】湖南太子奶乳酸菌180ml整箱8瓶童年记忆好味道









