<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP, Mysql e Jquery</title>
	<atom:link href="http://www.phpmysqljquery.com.br/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpmysqljquery.com.br</link>
	<description>PHP, Mysql e Jquery de uma maneira descomplicada</description>
	<lastBuildDate>Sun, 29 Jan 2012 14:31:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Nova Função para baixar videos do Youtube utilizando PHP &#8211; Janeiro 2012</title>
		<link>http://www.phpmysqljquery.com.br/php/nova-funcao-para-baixar-videos-do-youtube-utilizando-php-janeiro-2012/</link>
		<comments>http://www.phpmysqljquery.com.br/php/nova-funcao-para-baixar-videos-do-youtube-utilizando-php-janeiro-2012/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 14:25:40 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[baixar]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[janeiro]]></category>
		<category><![CDATA[nova]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[quality]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=69</guid>
		<description><![CDATA[Olá pessoal, estou disponibilizando aqui uma função que eu fiz para baixar video do Youtube, com esta função você pode escolher até a qualidade e o tipo de video. A url do Youtube pode estar em qualquer formato. Segue abaixo a função atualizada para 01/2012: &#60;?php /** @author Leandro Alves Moreira &#60;contato@killme.com.br&#62; @param string $video_url [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal, estou disponibilizando aqui uma função que eu fiz para baixar video do Youtube, com esta função você pode escolher até a qualidade e o tipo de video. A url do Youtube pode estar em qualquer formato. Segue abaixo a função atualizada para 01/2012:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #009933; font-style: italic;">/**
    @author Leandro Alves Moreira &lt;contato@killme.com.br&gt;
    @param string $video_url Url do video em qualquer formato
    @param string $video_savepath Caminho em que sera salvo o arquivo, se nao
    for setado, ele ira salvar no mesmo diretorio do arquivo.
    @param string $video_filename Nome do arquivo sem extensao, se nao for
    setado o nome sera o id do video no Youtube
    @param string $video_quality Qualidade do video, opcoes: hd1080,hd720,large,medium,small
    @param string $video_type Tipo de video, opcoes: video/mp4, video/webm, video/x-flv
    @name getYoutubeVideo
    @return bool
    @version 2012-01-29
    Download videos Youtube
    **/</span>
    <span style="color: #000000; font-weight: bold;">function</span> getYoutubeVideo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_savepath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_quality</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_type</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//setando algumas variaveis</span>
        <span style="color: #000088;">$video_ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'video/mp4'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'mp4'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'video/webm'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'webm'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'video/x-flv'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'flv'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$video_url_dl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$video_found</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$video_options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//validando parametros da funcao</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">filter_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_url</span><span style="color: #339933;">,</span> FILTER_VALIDATE_URL<span style="color: #339933;">,</span> FILTER_FLAG_SCHEME_REQUIRED<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//pegando html da pagina do youtube</span>
            <span style="color: #000088;">$youtube_page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//procurando trecho do codigo em JSON</span>
            <span style="color: #000088;">$data1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yt.playerConfig = &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$youtube_page</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$data2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yt.setConfig({&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$data1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//atribuindo somente o JSON a uma variavel</span>
            <span style="color: #000088;">$youtube_json</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//decodificando JSON para Objeto</span>
            <span style="color: #000088;">$youtube_json_decoded</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">html_entity_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtube_json</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//inserindo as urls dos videos em um array</span>
            <span style="color: #000088;">$youtube_video_urls</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$youtube_json_decoded</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url_encoded_fmt_stream_map</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtube_video_urls</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">//pegando somente a parte que interessa</span>
                <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">';'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">//sobrescrevendo em cima da mesma informacao</span>
                <span style="color: #000088;">$youtube_video_urls</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
            <span style="color: #666666; font-style: italic;">//verifica a qualidade selecionada do video, se a qualidade nao existir no youtube</span>
            <span style="color: #666666; font-style: italic;">//ou nenhuma for selecionada, a melhor qualidade sera escolhida</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_quality</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_quality</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'hd1080'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'hd720'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'large'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'medium'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'small'</span><span style="color: #339933;">:</span>
                        <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video_quality</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                        <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'hd1080'</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'hd1080'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
            <span style="color: #666666; font-style: italic;">//verifica o tipo do video, se tipo nao existir no youtube</span>
            <span style="color: #666666; font-style: italic;">//ou nenhum for selecionado, mp4 sera escolhida</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'video/mp4'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'video/webm'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'video/x-flv'</span><span style="color: #339933;">:</span>
                        <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video_type</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                        <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'video/mp4'</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'video/mp4'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//procurando video</span>
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtube_video_urls</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #000088;">$parsed_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parsed_url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;query&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parsed_query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parsed_query</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parsed_query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$video_found</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$video_url_dl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//se o nome do arquivo nao for setado</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_filename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$youtube_json_decoded</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">video_id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span><span style="color: #000088;">$video_ext</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video_filename</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span><span style="color: #000088;">$video_ext</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//se o caminho para salvar o arquivo nao for setado</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_savepath</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_savepath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_savepath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_savepath</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video_savepath</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//se o video foi encontrado</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_found</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_stream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_url_dl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_stream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtube_video_urls</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//fazendo download do video e salvando</span>
            <span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_savepath</span><span style="color: #339933;">.</span><span style="color: #000088;">$video_filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Exemplo de uso:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">getYoutubeVideo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.youtube.com/watch?v=nm42UBPnpxI&amp;feature=mh_lolz&amp;list=FLwT0FQqRkWv3Tni9SlrEQuw'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'video/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'teste2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hd720'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'video/mp4'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;</p>
<p>Essa função já está funcionando com a nova versão 2012 do Youtube, críticas, sugestões e melhorias no código podem ser postadas nos comentários. Obrigado.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/php/nova-funcao-para-baixar-videos-do-youtube-utilizando-php-janeiro-2012/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Função para baixar videos do Youtube utilizando PHP</title>
		<link>http://www.phpmysqljquery.com.br/php/funcao-para-baixar-videos-do-youtube-utilizando-php/</link>
		<comments>http://www.phpmysqljquery.com.br/php/funcao-para-baixar-videos-do-youtube-utilizando-php/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 03:04:38 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[baixar]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[quality]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=61</guid>
		<description><![CDATA[Atenção, essa função já não funciona mais no youtube, segue o link desta função atualizada: Nova Função para baixar videos do Youtube utilizando PHP – Janeiro 2012 Olá pessoal, estou disponibilizando aqui uma função que eu fiz para baixar video do Youtube, com esta função você pode escolher até a qualidade e o tipo de [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">Atenção, essa função já não funciona mais no youtube, segue o link desta função atualizada:</span> <a title="Nova Função para baixar videos do Youtube utilizando PHP – Janeiro 2012" href="http://www.phpmysqljquery.com.br/php/nova-funcao-para-baixar-videos-do-youtube-utilizando-php-janeiro-2012/">Nova Função para baixar videos do Youtube utilizando PHP – Janeiro 2012</a></p>
<p><del datetime="2012-01-29T14:25:49+00:00">Olá pessoal, estou disponibilizando aqui uma função que eu fiz para baixar video do Youtube, com esta função você pode escolher até a qualidade e o tipo de video. A url do Youtube pode estar em qualquer formato. Segue abaixo a função:</del></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span>?php 
<span style="color: #009933; font-style: italic;">/**
    @author Leandro Alves Moreira &lt;contato@killme.com.br--&gt;
    @param string $video_url Url do video em qualquer formato
    @param string $video_savepath Caminho em que sera salvo o arquivo, se nao
    for setado, ele ira salvar no mesmo diretorio do arquivo.
    @param string $video_filename Nome do arquivo sem extensao, se nao for
    setado o nome sera o id do video no Youtube
    @param string $video_quality Qualidade do video, opcoes: hd1080,hd720,large,medium,small
    @param string $video_type Tipo de video, opcoes: video/mp4, video/webm, video/x-flv
    @name getYoutubeVideo
    @return bool
    @version 2011-08-26
    Download videos Youtube
    **/</span>
    <span style="color: #000000; font-weight: bold;">function</span> getYoutubeVideo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_savepath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_quality</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_type</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//setando algumas variaveis</span>
        <span style="color: #000088;">$video_ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'video/mp4'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'mp4'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'video/webm'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'webm'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'video/x-flv'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'flv'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$video_url_dl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$video_found</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$video_options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//validando parametros da funcao</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">filter_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_url</span><span style="color: #339933;">,</span> FILTER_VALIDATE_URL<span style="color: #339933;">,</span> FILTER_FLAG_SCHEME_REQUIRED<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//pegando html da pagina do youtube</span>
            <span style="color: #000088;">$youtube_page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//procurando trecho do codigo em JSON</span>
            <span style="color: #000088;">$data1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'PLAYER_CONFIG': &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$youtube_page</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$data2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;  });&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$data1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//atribuindo somente o JSON a uma variavel</span>
            <span style="color: #000088;">$youtube_json</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//decodificando JSON para Objeto</span>
            <span style="color: #000088;">$youtube_json_decoded</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">html_entity_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtube_json</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//inserindo as urls dos videos em um array</span>
            <span style="color: #000088;">$youtube_video_urls</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$youtube_json_decoded</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url_encoded_fmt_stream_map</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtube_video_urls</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">//pegando somente a parte que interessa</span>
                <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">';'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">//sobrescrevendo em cima da mesma informacao</span>
                <span style="color: #000088;">$youtube_video_urls</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//verifica a qualidade selecionada do video, se a qualidade nao existir no youtube</span>
            <span style="color: #666666; font-style: italic;">//ou nenhuma for selecionada, a melhor qualidade sera escolhida</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_quality</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_quality</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'hd1080'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'hd720'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'large'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'medium'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'small'</span><span style="color: #339933;">:</span>
                        <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video_quality</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                        <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'hd1080'</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'hd1080'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//verifica o tipo do video, se tipo nao existir no youtube</span>
            <span style="color: #666666; font-style: italic;">//ou nenhum for selecionado, mp4 sera escolhida</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'video/mp4'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'video/webm'</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'video/x-flv'</span><span style="color: #339933;">:</span>
                        <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video_type</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                        <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'video/mp4'</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'video/mp4'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//procurando video</span>
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtube_video_urls</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #000088;">$parsed_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parsed_url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;query&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parsed_query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parsed_query</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parsed_query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$video_found</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$video_url_dl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//se o nome do arquivo nao for setado</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_filename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$youtube_json_decoded</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">video_id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span><span style="color: #000088;">$video_ext</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video_filename</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span><span style="color: #000088;">$video_ext</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$video_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//se o caminho para salvar o arquivo nao for setado</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_savepath</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_savepath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_savepath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_savepath</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video_savepath</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//se o video foi encontrado</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_found</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_stream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_url_dl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$video_stream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$youtube_video_urls</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//fazendo download do video e salvando</span>
            <span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$video_savepath</span><span style="color: #339933;">.</span><span style="color: #000088;">$video_filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$video_stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Exemplo de uso:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">getYoutubeVideo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.youtube.com/watch?v=nm42UBPnpxI&amp;feature=mh_lolz&amp;list=FLwT0FQqRkWv3Tni9SlrEQuw'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'video/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'teste2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hd720'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'video/mp4'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;</p>
<p><del datetime="2012-01-29T14:25:49+00:00">Essa função já está funcionando com a nova versão 2011 do Youtube, críticas, sugestões e melhorias no código podem ser postadas nos comentários. Obrigado.</del></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/php/funcao-para-baixar-videos-do-youtube-utilizando-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Formatando moeda Real no Javascript e Jquery</title>
		<link>http://www.phpmysqljquery.com.br/jquery/formatando-moeda-real-no-javascript-e-jquery/</link>
		<comments>http://www.phpmysqljquery.com.br/jquery/formatando-moeda-real-no-javascript-e-jquery/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 12:59:14 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[formatar]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[moeda]]></category>
		<category><![CDATA[reais]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=59</guid>
		<description><![CDATA[Formatar moeda no Javascript ou Jquery é muito fácil: function reais&#40;num&#41;&#123; num = num.replace&#40;&#34;.&#34;,&#34;&#34;&#41;; num = num.replace&#40;&#34;,&#34;,&#34;.&#34;&#41;; return parseFloat&#40;num&#41;; &#125;]]></description>
			<content:encoded><![CDATA[<p>Formatar moeda no Javascript ou Jquery é muito fácil:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> reais<span style="color: #009900;">&#40;</span>num<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   num <span style="color: #339933;">=</span> num.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   num <span style="color: #339933;">=</span> num.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">return</span> parseFloat<span style="color: #009900;">&#40;</span>num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/jquery/formatando-moeda-real-no-javascript-e-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Formatando moeda no Smarty, frameworks para PHP</title>
		<link>http://www.phpmysqljquery.com.br/php/formatando-moeda-no-smarty-frameworks-para-php/</link>
		<comments>http://www.phpmysqljquery.com.br/php/formatando-moeda-no-smarty-frameworks-para-php/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 12:52:29 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[moeda]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[reais]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=57</guid>
		<description><![CDATA[Formatar moeda no framework Smarty é muito fácil, veja a seguir: &#123;$value&#124;number_format:2:&#34;,&#34;:&#34;.&#34;&#125;]]></description>
			<content:encoded><![CDATA[<p>Formatar moeda no framework Smarty é muito fácil, veja a seguir:</p>

<div class="wp_syntax"><div class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #D36900;">&#123;</span><span style="color: #00aaff;">$value</span>|number_format:<span style="color: #cc66cc;">2</span>:<span style="color: #ff0000;">&quot;,&quot;</span>:<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #D36900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/php/formatando-moeda-no-smarty-frameworks-para-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatar moeda Real no PHP usando money_format</title>
		<link>http://www.phpmysqljquery.com.br/php/formatar-moeda-real-no-php-usando-money_format/</link>
		<comments>http://www.phpmysqljquery.com.br/php/formatar-moeda-real-no-php-usando-money_format/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 12:47:57 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[dinheiro]]></category>
		<category><![CDATA[formatar]]></category>
		<category><![CDATA[moeda]]></category>
		<category><![CDATA[money_format]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[reais]]></category>
		<category><![CDATA[real]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=52</guid>
		<description><![CDATA[Formatar moedas no PHP é muito fácil, veja como fazer isto utilizando a função money_format(). &#60;?php $valor = 87946.00; echo number_format&#40;$valor,2,',','.'&#41;; ?&#62; O resultado será: 87.946,00]]></description>
			<content:encoded><![CDATA[<p>Formatar moedas no PHP é muito fácil, veja como fazer isto utilizando a função <a href="http://www.php.net/manual/pt_BR/function.money-format.php">money_format()</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$valor</span> <span style="color: #339933;">=</span> <span style="color:#800080;">87946.00</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$valor</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>O resultado será: <strong>87.946,00</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/php/formatar-moeda-real-no-php-usando-money_format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatar moeda Real no PHP usando number_format</title>
		<link>http://www.phpmysqljquery.com.br/php/formatar-moeda-real-no-php-usando-number-format/</link>
		<comments>http://www.phpmysqljquery.com.br/php/formatar-moeda-real-no-php-usando-number-format/#comments</comments>
		<pubDate>Fri, 08 Apr 2011 16:41:28 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[formatar]]></category>
		<category><![CDATA[moeda]]></category>
		<category><![CDATA[number_format]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[reais]]></category>
		<category><![CDATA[real]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=44</guid>
		<description><![CDATA[Formatar moedas no PHP é muito fácil, veja como fazer isto utilizando a função number_format(). &#60;?php $valor = 87946.00; echo number_format&#40;$valor,2,',','.'&#41;; ?&#62; O resultado será: 87.946,00]]></description>
			<content:encoded><![CDATA[<p>Formatar moedas no PHP é muito fácil, veja como fazer isto utilizando a função <a href="http://php.net/manual/en/function.number-format.php">number_format()</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$valor</span> <span style="color: #339933;">=</span> <span style="color:#800080;">87946.00</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$valor</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>O resultado será: <strong>87.946,00</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/php/formatar-moeda-real-no-php-usando-number-format/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Separando URLs açucaradas em um array com PHP</title>
		<link>http://www.phpmysqljquery.com.br/php/separando-urls-acucaradas-em-um-array-com-php/</link>
		<comments>http://www.phpmysqljquery.com.br/php/separando-urls-acucaradas-em-um-array-com-php/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 18:33:32 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[açucaradas]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[array_filter]]></category>
		<category><![CDATA[array_values]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=41</guid>
		<description><![CDATA[Com esta função abaixo você consegue pegar a URL atual e separar com um array para poder usar como quiser. function get_url_array&#40;&#41; &#123; $url = array_values&#40;array_filter&#40;explode&#40;&#34;/&#34;,str_replace&#40;strrchr&#40;$_SERVER&#91;&#34;REQUEST_URI&#34;&#93;, &#34;?&#34;&#41;, &#34;&#34;, $_SERVER&#91;&#34;REQUEST_URI&#34;&#93;&#41;&#41;&#41;&#41;; return $url; &#125; Uma URL como esta: http://www.phpmysqljquery.com.br/level1/level2/level3/level4/level5 irá retornar algo assim: Array(0=>&#8217;level1&#8242;,1=>&#8217;level2&#8242;,2=>&#8217;level3&#8242;,3=>&#8217;level4&#8242;,4=>&#8217;level5&#8242;). Fique sempre atento a documentação do PHP, MySQL e jQuery. Até mais.]]></description>
			<content:encoded><![CDATA[<p>Com esta função abaixo você consegue pegar a URL atual e separar com um array para poder usar como quiser.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_url_array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrchr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$url</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Uma URL como esta: <strong>http://www.phpmysqljquery.com.br/level1/level2/level3/level4/level5</strong> irá retornar algo assim: <strong>Array(0=>&#8217;level1&#8242;,1=>&#8217;level2&#8242;,2=>&#8217;level3&#8242;,3=>&#8217;level4&#8242;,4=>&#8217;level5&#8242;)</strong>.</p>
<p>Fique sempre atento a documentação do <a href="http://www.php.net/manual/en/">PHP</a>, <a href="http://dev.mysql.com/doc/refman/5.0/en/">MySQL</a> e <a href="http://docs.jquery.com/Main_Page">jQuery</a>. Até mais.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/php/separando-urls-acucaradas-em-um-array-com-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Separando URLs açucaradas em um array com Javascript</title>
		<link>http://www.phpmysqljquery.com.br/javascript/separando-urls-acucaradas-em-um-array-com-javascript/</link>
		<comments>http://www.phpmysqljquery.com.br/javascript/separando-urls-acucaradas-em-um-array-com-javascript/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 02:11:16 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[açucaradas]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[separando]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[urls]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=36</guid>
		<description><![CDATA[Com esta função abaixo você consegue pegar a URL atual e separar com um array para poder usar como quiser. Geralmente eu uso para fazer algum tipo de ação em alguma página que sei a URL. function get_url_array&#40;&#41; &#123; url = window.location; url = url.toString&#40;&#41;; url = url.split&#40;'/'&#41;; url.splice&#40;0,3&#41;; return url; &#125; Uma URL como [...]]]></description>
			<content:encoded><![CDATA[<p>Com esta função abaixo você consegue pegar a URL atual e separar com um array para poder usar como quiser. Geralmente eu uso para fazer algum tipo de ação em alguma página que sei a URL.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> get_url_array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    url <span style="color: #339933;">=</span> window.<span style="color: #660066;">location</span><span style="color: #339933;">;</span>
    url <span style="color: #339933;">=</span> url.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    url <span style="color: #339933;">=</span> url.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    url.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> url<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Uma URL como esta: <strong>http://www.phpmysqljquery.com.br/level1/level2/level3/level4/level5</strong> irá retornar algo assim: <strong>Array(&#8216;level1&#8242;,&#8217;level2&#8242;,&#8217;level3&#8242;,&#8217;level4&#8242;,&#8217;level5&#8242;)</strong>.</p>
<p>Fique sempre atento a documentação do <a href="http://www.php.net/manual/en/">PHP</a>, <a href="http://dev.mysql.com/doc/refman/5.0/en/">MySQL</a> e <a href="http://docs.jquery.com/Main_Page">jQuery</a>. Até mais.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/javascript/separando-urls-acucaradas-em-um-array-com-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convertendo datas no formato string para o formato de data do MySQL com o str_to_date</title>
		<link>http://www.phpmysqljquery.com.br/mysql/convertendo-datas-no-formato-string-para-o-formato-de-data-do-mysql-com-o-str_to_date/</link>
		<comments>http://www.phpmysqljquery.com.br/mysql/convertendo-datas-no-formato-string-para-o-formato-de-data-do-mysql-com-o-str_to_date/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 02:07:46 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[convertendo]]></category>
		<category><![CDATA[datas]]></category>
		<category><![CDATA[formato]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[str_to_date]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=34</guid>
		<description><![CDATA[Se você precisa converter aquela data esquisita que só você entende para um formato padrão usado no MySQL, preste atenção logo abaixo: SELECT STR_TO_DATE&#40;'Dec/22/2010', '%M/%d/%Y'&#41; as date; Retorna: 2010-12-22 SELECT STR_TO_DATE&#40;'Dec/22/2010 10:11', '%M/%d/%Y'&#41; as date; Retorna: 2010-12-22 10:11:00 Basta você mostrar a data e dar um layout a ela e depois ver o resultado. Isto [...]]]></description>
			<content:encoded><![CDATA[<p>Se você precisa converter aquela data esquisita que só você entende para um formato padrão usado no MySQL, preste atenção logo abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">STR_TO_DATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'Dec/22/2010'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>M/<span style="color: #008080; font-weight: bold;">%</span>d/<span style="color: #008080; font-weight: bold;">%</span>Y'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">as</span> <span style="color: #999900; font-weight: bold;">date</span><span style="color: #000033;">;</span></pre></div></div>

<p><strong>Retorna: 2010-12-22</strong></p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">STR_TO_DATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'Dec/22/2010 10:11'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>M/<span style="color: #008080; font-weight: bold;">%</span>d/<span style="color: #008080; font-weight: bold;">%</span>Y'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">as</span> <span style="color: #999900; font-weight: bold;">date</span><span style="color: #000033;">;</span></pre></div></div>

<p><strong>Retorna: 2010-12-22 10:11:00</strong></p>
<p>Basta você mostrar a data e dar um layout a ela e depois ver o resultado. Isto pode ser usado em qualquer tipo de Query.</p>
<p>As funções usadas do MySQL foram:<a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date">STR_TO_DATE</a>. Fique sempre atento a documentação do <a href="http://www.php.net/manual/en/">PHP</a>, <a href="http://dev.mysql.com/doc/refman/5.0/en/">MySQL</a> e <a href="http://docs.jquery.com/Main_Page">jQuery</a>. Até mais.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/mysql/convertendo-datas-no-formato-string-para-o-formato-de-data-do-mysql-com-o-str_to_date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Datas no formato de arquivo de sitemap ou ISO 8601 no PHP</title>
		<link>http://www.phpmysqljquery.com.br/php/datas-no-formato-de-arquivo-de-sitemap-ou-iso-8601-no-php/</link>
		<comments>http://www.phpmysqljquery.com.br/php/datas-no-formato-de-arquivo-de-sitemap-ou-iso-8601-no-php/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 01:23:26 +0000</pubDate>
		<dc:creator>Leandro Alves</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[8601]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[formato]]></category>
		<category><![CDATA[iso]]></category>
		<category><![CDATA[iso 8601]]></category>
		<category><![CDATA[sitemap]]></category>

		<guid isPermaLink="false">http://www.phpmysqljquery.com.br/?p=32</guid>
		<description><![CDATA[Olá, no PHP 4 para fazer datas para os meus sitemaps eu utilizava uma gambiarra feia pra caramba, pois segundo as normas o tipo de data utilizado na maioria deles é a ISO 8601, ou seja, neste formato aqui: 2004-02-12T15:19:21+00:00 Então eu tinha de fazer algo como: &#60;?php echo date&#40;'Y-m-d\TH:i:sP'&#41;; ?&#62; Mas agora no PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Olá, no PHP 4 para fazer datas para os meus sitemaps eu utilizava uma gambiarra feia pra caramba, pois segundo as normas o tipo de data utilizado na maioria deles é a ISO 8601, ou seja, neste formato aqui: <strong>2004-02-12T15:19:21+00:00</strong></p>
<p>Então eu tinha de fazer algo como:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d\TH:i:sP'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Mas agora no PHP 5 não é mais necessário, basta fazer:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Simples não?</p>
<p>As funções usadas do PHP foram: <a href="http://php.net/manual/en/function.date.php">date</a>. Fique sempre atento a documentação do <a href="http://www.php.net/manual/en/">PHP</a>, <a href="http://dev.mysql.com/doc/refman/5.0/en/">MySQL</a> e <a href="http://docs.jquery.com/Main_Page">jQuery</a>. Até mais.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpmysqljquery.com.br/php/datas-no-formato-de-arquivo-de-sitemap-ou-iso-8601-no-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

