{"id":1933,"date":"2014-09-12T19:07:53","date_gmt":"2014-09-12T10:07:53","guid":{"rendered":"http:\/\/taitan916.info\/blog\/?p=1933"},"modified":"2024-04-17T13:55:18","modified_gmt":"2024-04-17T04:55:18","slug":"post-1933","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/1933","title":{"rendered":"PHP\u3067\u30b5\u30a4\u30c8URL\u304b\u3089title\u3068RSS\u7528URL\u3092\u53d6\u5f97"},"content":{"rendered":"<p>\u30b5\u30a4\u30c8\u306eURL\u304b\u3089RSS\u7528URL\u3068\u30b5\u30a4\u30c8\u30bf\u30a4\u30c8\u30eb\u3092\u81ea\u52d5\u3067\u53d6\u5f97\u3057\u305f\u304b\u3063\u305f\u3002\u305d\u306e\u65b9\u6cd5\u306e\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nfunction findFeedUrl( $url ){\r\n    if ( !$url ) return false;\r\n\r\n    $html = file_get_contents($url);\r\n\r\n    if( !$html ) return false;\r\n\r\n    $title = (preg_match('\/&lt;title&gt;(.*?)&lt;\\\/title&gt;\/i', mb_convert_encoding($html, 'UTF-8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS'), $result)) ? $result[1] : '';\r\n\r\n    preg_match_all('\/&lt;link\\s+(.*?)\\s*\\\/?&gt;\/is', $html, $matches);\r\n    $links = $matches[1];\r\n    $finalLinks = array();\r\n    foreach ($links as $idx=&gt;$link) {\r\n        $attributes = preg_split('\/\\s+\/s', $link);\r\n        foreach ($attributes as $attribute) {\r\n            $att = preg_split('\/\\s*=\\s*\/s', $attribute, 2);\r\n            if(isset($att[1])) {\r\n                $att[1] = preg_replace('\/([\\'\"]?)(.*)\\1\/', '$2', $att[1]);\r\n                $finalLink[strtolower($att[0])] = $att[1];\r\n            }\r\n        }\r\n        $finalLinks[$idx] = $finalLink;\r\n    }\r\n\r\n    $href = null;\r\n    foreach ($finalLinks as $finalLink) {\r\n        if (!array_key_exists('type', $finalLink)) {\r\n            continue;\r\n        }\r\n        switch (strtolower($finalLink['type'])) {\r\n        case 'application\/x.atom+xml':\r\n        case 'application\/atom+xml':\r\n        case 'application\/xml':\r\n        case 'text\/xml':\r\n        case 'application\/rss+xml':\r\n        case 'application\/rdf+xml':\r\n            if (array_key_exists('href', $finalLink)) {\r\n                $href = $finalLink['href'];\r\n            }\r\n            break;\r\n        default:\r\n            break;\r\n        }\r\n\r\n        if ($href) {\r\n            if (strstr($href, 'http:\/\/') !== false) {\r\n                $fullUrl = $href;\r\n            } else {\r\n                $urlParts = parse_url($url);\r\n                $fullUrl = \"http:\/\/{$urlParts['host']}\";\r\n                if (isset($urlParts['port'])) {\r\n                    $fullUrl .= \":{$urlParts['port']}\";\r\n                }\r\n                if ($href{0} != '\/'){\r\n                    if (isset($urlParts['path'])) {\r\n                        $fullUrl .= dirname($urlParts['path']);\r\n                    }\r\n                    if (substr($fullUrl, -1) != '\/') {\r\n                        $fullUrl .= '\/';\r\n                    }\r\n                }\r\n                $fullUrl .= $href;\r\n            }\r\n            return array($fullUrl, $title);\r\n        }\r\n    }\r\n\r\n    return false;\r\n}\r\n\r\nvar_dump(findFeedUrl('https:\/\/taitan916.info\/blog\/')); \/\/array(2) { [0]=&gt; string(37) \"https:\/\/taitan916.info\/blog\/?feed=rss2\" [1]=&gt; string(30) \"\u52c9\u5f37\u3057\u305f\u3053\u3068\u306e\u30e1\u30e2\u3002\" }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30b5\u30a4\u30c8\u306eURL\u304b\u3089RSS\u7528URL\u3068\u30b5\u30a4\u30c8\u30bf\u30a4\u30c8\u30eb\u3092\u81ea\u52d5\u3067\u53d6\u5f97\u3057\u305f\u304b\u3063\u305f\u3002\u305d\u306e\u65b9\u6cd5 ... <\/p>\n","protected":false},"author":1,"featured_media":1085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/1933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=1933"}],"version-history":[{"count":1,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/1933\/revisions"}],"predecessor-version":[{"id":5855,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/1933\/revisions\/5855"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1085"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=1933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=1933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=1933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}