{"id":1253,"date":"2012-07-23T11:23:32","date_gmt":"2012-07-23T02:23:32","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=1253"},"modified":"2019-04-10T11:44:23","modified_gmt":"2019-04-10T02:44:23","slug":"post-1253","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/php\/1253","title":{"rendered":"\u3010PHP\u3011 YouTube\u306eURL\u3092\u89e3\u6790\u3057\u3066iframe\u3092\u4f5c\u6210\u3059\u308b"},"content":{"rendered":"<p>YouTube\u52d5\u753b\u306eURL\u3092\u6e21\u3059\u3068iframe\u30bf\u30b0\u306b\u3057\u3066\u8fd4\u3057\u3066\u304f\u308c\u308b\u95a2\u6570<br \/>\n<span class=\"removed_link\" title=\"http:\/\/blogfreakz.com\/tutorial\/parse-youtube-urls-with-php\/\">PARSE YOUTUBE URLS WITH PHP<\/span><\/p>\n<pre class=\"lang:php decode:true \" >function parseYoutubeURL($link, $width=640, $height=360){\n    $final = ' &lt;iframe width=&quot;'.$width.'&quot; height=&quot;'.$height.'&quot; src=&quot;http:\/\/www.youtube.com\/embed\/{code}&quot; frameborder=&quot;0&quot;&gt;&lt;\/iframe&gt;';\n    \n    \/\/se o link for o embed (altera o width e height)\n    \n    if(stristr($link, &quot;iframe&quot;)){\n        $link = preg_replace(&quot;\/width=(\\&quot;)[0-9]+(\\&quot;)\/&quot;, 'width=&quot;'.$width.'&quot;', $link);\n        $link = preg_replace(&quot;\/height=(\\&quot;)[0-9]+(\\&quot;)\/&quot;, 'height=&quot;'.$height.'&quot;', $link);\n        return $link;\n    }\n\n    $parsed = parse_url($link);\n    \/\/link URL\n    if(stristr($parsed['path'], 'watch') !== false){\n        parse_str($parsed['query'], $args);\n        $code = $args['v'];\n    }\/\/link do embbed\n    elseif(stristr($parsed['path'], 'embed') !== false){\n        $code = str_replace(&quot;\/embed\/&quot;, &quot;&quot;, $parsed['path']);\n    }\/\/short link   \n    elseif($parsed['host'] == 'youtu.be'){\n        $code = str_replace(&quot;\/&quot;, &quot;&quot;, $parsed['path']);\n    }\n    \n    \n    if($code){\n        $final = str_replace(&quot;{code}&quot;, $code, $final);\n        return $final;\n    }else{\n        return null;\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>YouTube\u52d5\u753b\u306eURL\u3092\u6e21\u3059\u3068iframe\u30bf\u30b0&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-1253","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/1253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=1253"}],"version-history":[{"count":4,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/1253\/revisions"}],"predecessor-version":[{"id":1257,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/1253\/revisions\/1257"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=1253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=1253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=1253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}