سلام
من میخواستم یه کد بنویسم که وقتی یه لینک به اسکریپت میدم سوررس اونو چک کنه و بگه که اون صفحه xml هست یا نه خودم این کد رو نوشتم ولی چون regex خرابه کار نمیکنه دوستان میتونن کمک کنن
ممنون میشم
خودم یه کد درست کردم لینک های صفحه رو نگاه میکنه هرکدوم که پسوند xml
داشته باشن رو پیدا میکنه ولی من میخوام از ذاخل سورس لینک ها بفهمه xml هستن یا نه
من دوتا عبارات منظم تگ های زیر رو میخوام یک
یک
<?xml version="1.0" encoding="utf-8" ?>
دو
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
ممنون میشم کمکم کنید
کد اول من
کد PHP:
<?PHP // Original PHP code by Chirp Internet: www.javacod.ir // Please acknowledge use of this code by including this header.
$url = "https://www.yjc.ir/fa/rss"; $input = file_get_contents($url) or die("Could not access file: $url"); $regexp = "(http|https|)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?\/[a-zA-Z0-9\-\.]+\.xml"; if(preg_match_all("/$regexp/siU", $input, $matches)) { // echo $matches[2]; // = array of link addresses // $matches[3] = array of link text - including HTML code print_r($matches[2]); print_r($matches[3]);
foreach($matches[2] as $k) { echo $k."<br>"; }}?>
کد دوم
کد PHP:
<?php$url = ('https://www.yjc.ir/fa/rss');$urlContent = file_get_contents($url);
//<?xml version="1.0" encoding="utf-8"?> //chek kone bebine tag zir toye sors hast ya na$chek1="\<\?.*?="(.*?)".*?="(.*?)"?\>";
// <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> // chk kone bebine in tag to sors hast y a na
$chek2="\<rss.*?version="(.*?)">|"; if (strstr($urlContent,$chek1) or strstr($urlContent,$chek2)){echo "ok";echo "xml link";}else{echo "no";echo "xml link";}
- - - Updated - - -
کسی نیست کمک کنه