<?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>ekimdusu.net &#187; fonksiyon</title>
	<atom:link href="http://www.ekimdusu.net/index.php/tag/fonksiyon/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ekimdusu.net</link>
	<description>Bazıları için düş, bazıları için gerçek.</description>
	<lastBuildDate>Thu, 29 Jul 2010 17:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP ile Dailymotion video bilgilerini almak</title>
		<link>http://www.ekimdusu.net/index.php/2010/02/06/php-ile-dailymotion-video-bilgilerini-almak/</link>
		<comments>http://www.ekimdusu.net/index.php/2010/02/06/php-ile-dailymotion-video-bilgilerini-almak/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 12:48:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bilgisayar]]></category>
		<category><![CDATA[dailymotion]]></category>
		<category><![CDATA[fonksiyon]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[video bilgileri]]></category>
		<category><![CDATA[xml parse]]></category>

		<guid isPermaLink="false">http://blog.cagdaspolat.com/?p=1005</guid>
		<description><![CDATA[Daha önce buradaki yazımda PHP ile YouTube linklerinden videolarının bilgilerini almayı açıklamıştım. Şimdi aynı şeyi DailyMotion&#8217;da anlatmanın sırası geldi. Olay DailyMotion&#8217;un verilen bir video linkinden o videonun başlığını, açıklamasını, videonun resmini eltmek. Yeni projemde bu tip bir olayla karşılaşınca araştırma yaptım, çeşitli kodlar denedim ve sonunda oluşturduğum sentez PHP fonksiyonla bu işlemlerin hepsini yapabilecek duruma [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ekimdusu.net/wp-content/uploads/2009/12/youtubefunction.jpg"><img title="youtubefunction" src="http://www.ekimdusu.net/wp-content/uploads/2009/12/youtubefunction.jpg" alt="" width="423" height="293" /></a></p>
<p>Daha önce <a href="http://blog.cagdaspolat.com/index.php/2009/12/27/php-ile-youtubeden-video-ile-ilgili-bilgi-alma/" target="_blank">buradaki yazımda</a> PHP ile YouTube linklerinden videolarının bilgilerini almayı açıklamıştım. Şimdi aynı şeyi DailyMotion&#8217;da anlatmanın sırası geldi. Olay DailyMotion&#8217;un verilen bir video linkinden o videonun başlığını, açıklamasını, videonun resmini eltmek. Yeni projemde bu tip bir olayla karşılaşınca araştırma yaptım, çeşitli kodlar denedim ve sonunda oluşturduğum sentez PHP fonksiyonla bu işlemlerin hepsini yapabilecek duruma geldim.</p>
<pre class="brush: php;">
function dailymotionParse($url)
 {
 $vidparser = parse_url($url);
 $video['id'] = substr($vidparser['path'], 7);
 $urlXML = &amp;quot;http://www.dailymotion.com/atom/video/&amp;quot;. $video['id'];
 $dailyValue = $this-&amp;gt;xml2array($urlXML);
 if( $dailyValue == null)
 $video['works']=&amp;quot;NO&amp;quot;;
 else
 {
 preg_match_all(&amp;quot;/&amp;lt;\s*img [^\&amp;gt;]*src\s*=\s*[\&amp;quot;\&amp;quot;']?([^\&amp;quot;\\'\s&amp;gt;]*)/i&amp;quot;, $dailyValue['feed']['entry']['summary'], $dailyImg);
 preg_match_all(&amp;quot;/(&amp;lt;p.*&amp;gt;)(\w.*)(&amp;lt;\/p&amp;gt;)/ismU&amp;quot;, $dailyValue['feed']['entry']['summary'], $dailyDesc);
 $video['img'] = $dailyImg[1][0];
 $video['title'] = $dailyValue['feed']['entry']['title'];
 $video['desc'] = $this-&amp;gt;limit_words( strip_tags( $dailyDesc[0][0] ), 15 );
 }

 return $video;
 }
</pre>
<p>Öncelikle bu fonksiyonun çalışması için 6. satırdaki xml2array() fonksiyonunun da kodlarınız arasında olması gerekir. Bu fonksiyon php.net&#8217;ten bulduğum herhangi bir XML&#8217;i PHP arraya dönüştüren fonksiyondan birisi. Bu fonksiyonu diğer XML veriler için de kullanabilirsiniz.</p>
<p><span id="more-5467"></span><img title="Daha fazla..." src="http://blog.cagdaspolat.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /></p>
<pre class="brush: php;">

    function xml2array($url, $get_attributes = 1, $priority = 'tag')
    {
        $contents = &amp;quot;&amp;quot;;
        if (!function_exists('xml_parser_create'))
        {
            return array ();
        }
        $parser = xml_parser_create('');
        if (!($fp = @ fopen($url, 'rb')))
        {
            return array ();
        }
        while (!feof($fp))
        {
            $contents .= fread($fp, 8192);
        }
        fclose($fp);
        xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, &amp;quot;UTF-8&amp;quot;);
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
        xml_parse_into_struct($parser, trim($contents), $xml_values);
        xml_parser_free($parser);
        if (!$xml_values)
            return; //Hmm...
        $xml_array = array ();
        $parents = array ();
        $opened_tags = array ();
        $arr = array ();
        $current = &amp;amp; $xml_array;
        $repeated_tag_index = array ();
        foreach ($xml_values as $data)
        {
            unset ($attributes, $value);
            extract($data);
            $result = array ();
            $attributes_data = array ();
            if (isset ($value))
            {
                if ($priority == 'tag')
                    $result = $value;
                else
                    $result['value'] = $value;
            }
            if (isset ($attributes) and $get_attributes)
            {
                foreach ($attributes as $attr =&amp;gt; $val)
                {
                    if ($priority == 'tag')
                        $attributes_data[$attr] = $val;
                    else
                        $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
                }
            }
            if ($type == &amp;quot;open&amp;quot;)
            {
                $parent[$level -1] = &amp;amp; $current;
                if (!is_array($current) or (!in_array($tag, array_keys($current))))
                {
                    $current[$tag] = $result;
                    if ($attributes_data)
                        $current[$tag . '_attr'] = $attributes_data;
                    $repeated_tag_index[$tag . '_' . $level] = 1;
                    $current = &amp;amp; $current[$tag];
                }
                else
                {
                    if (isset ($current[$tag][0]))
                    {
                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
                        $repeated_tag_index[$tag . '_' . $level]++;
                    }
                    else
                    {
                        $current[$tag] = array (
                            $current[$tag],
                            $result
                        );
                        $repeated_tag_index[$tag . '_' . $level] = 2;
                        if (isset ($current[$tag . '_attr']))
                        {
                            $current[$tag]['0_attr'] = $current[$tag . '_attr'];
                            unset ($current[$tag . '_attr']);
                        }
                    }
                    $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
                    $current = &amp;amp; $current[$tag][$last_item_index];
                }
            }
            elseif ($type == &amp;quot;complete&amp;quot;)
            {
                if (!isset ($current[$tag]))
                {
                    $current[$tag] = $result;
                    $repeated_tag_index[$tag . '_' . $level] = 1;
                    if ($priority == 'tag' and $attributes_data)
                        $current[$tag . '_attr'] = $attributes_data;
                }
                else
                {
                    if (isset ($current[$tag][0]) and is_array($current[$tag]))
                    {
                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
                        if ($priority == 'tag' and $get_attributes and $attributes_data)
                        {
                            $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
                        }
                        $repeated_tag_index[$tag . '_' . $level]++;
                    }
                    else
                    {
                        $current[$tag] = array (
                            $current[$tag],
                            $result
                        );
                        $repeated_tag_index[$tag . '_' . $level] = 1;
                        if ($priority == 'tag' and $get_attributes)
                        {
                            if (isset ($current[$tag . '_attr']))
                            {
                                $current[$tag]['0_attr'] = $current[$tag . '_attr'];
                                unset ($current[$tag . '_attr']);
                            }
                            if ($attributes_data)
                            {
                                $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
                            }
                        }
                        $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
                    }
                }
            }
            elseif ($type == 'close')
            {
                $current = &amp;amp; $parent[$level -1];
            }
        }
        return ($xml_array);
    }
</pre>
<p>Bundan sonra kendi kodlarınız içinde youtubeParse() fonksiyonunu çağırıp bir değişkene atadığınızda, o array değişkeninin içeriğini kullanarak amacınıza ulaşmış olursunuz.</p>
<pre class="brush: php;">
$result = dailymotionParse(&amp;quot;http://www.dailymotion.com/video/x8crzz_yylmaz-erdoyan-etme-wwwatesclupcom_music&amp;quot;);
if ( $result['works'] == &amp;quot;NO&amp;quot; )
echo &amp;quot;Video bulunamadı&amp;quot;;
else
{
//videonun başlığı
echo $result['title'];

//videonun açıklaması, türkçe karaktere göre düzenlenmiştir
echo $result['desc'];

//videonun resmi
echo $result['img'];
}
</pre>
<p>Temel olarak yaptığımız şey, her videoya ait RSS beslemesine girip oradaki bilgileri işimize yarayacak şekilde elemek oldu(parse).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ekimdusu.net/index.php/2010/02/06/php-ile-dailymotion-video-bilgilerini-almak/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP ile YouTube&#039;den video ile ilgili bilgi alma</title>
		<link>http://www.ekimdusu.net/index.php/2009/12/27/php-ile-youtubeden-video-ile-ilgili-bilgi-alma/</link>
		<comments>http://www.ekimdusu.net/index.php/2009/12/27/php-ile-youtubeden-video-ile-ilgili-bilgi-alma/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 13:03:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bilgisayar]]></category>
		<category><![CDATA[fonksiyon]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml parse]]></category>
		<category><![CDATA[YouTube]]></category>

		<guid isPermaLink="false">http://blog.cagdaspolat.com/?p=971</guid>
		<description><![CDATA[Kendi geliştirdiğiniz uygulamanızda kullanıcılarınızın veya sizin gireceğiniz YouTube linkinden(örnek: http://www.youtube.com/watch?v=0peX66dC6Sk) o videonun başlığını, açıklamasını, videonun resmini elde edip bunu kullanmak isteyebilirsiniz. Yeni projemde bu tip bir olayla karşılaşınca araştırma yaptım, çeşitli kodlar denedim ve sonunda oluşturduğum sentez PHP fonksiyonla bu işlemlerin hepsini yapabilecek duruma geldim. function youtubeParse($url) { $vidparser = parse_url($url); $video['id'] = substr($vidparser['query'], 2); [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ekimdusu.net/wp-content/uploads/2009/12/youtubefunction.jpg"><img class="alignnone size-full wp-image-979" title="youtubefunction" src="http://www.ekimdusu.net/wp-content/uploads/2009/12/youtubefunction.jpg" alt="" width="423" height="293" /></a></p>
<p>Kendi geliştirdiğiniz uygulamanızda kullanıcılarınızın veya sizin gireceğiniz YouTube linkinden(örnek: http://www.youtube.com/watch?v=0peX66dC6Sk) o videonun başlığını, açıklamasını, videonun resmini elde edip bunu kullanmak isteyebilirsiniz. Yeni projemde bu tip bir olayla karşılaşınca araştırma yaptım, çeşitli kodlar denedim ve sonunda oluşturduğum sentez PHP fonksiyonla bu işlemlerin hepsini yapabilecek duruma geldim.</p>
<pre class="brush: php;">
function youtubeParse($url)
{
$vidparser = parse_url($url);
$video['id'] = substr($vidparser['query'], 2);
$urlXML = &quot;http://gdata.youtube.com/feeds/api/videos/&quot;. $video['id'];
$youtubeValue = xml2array($urlXML);
if( $youtubeValue == null)
$video['works']=&quot;NO&quot;;
else
{
$video['title'] = iconv(&quot;UTF-8&quot;, &quot;ISO-8859-9&quot;, $youtubeValue['entry']['title']);
$desc = $youtubeValue['entry']['content'];
$video['img'] = &quot;http://img.youtube.com/vi/&quot; . $video['id'] . &quot;/1.jpg&quot;;
$video['desc'] = $this-&gt;limit_words(iconv(&quot;UTF-8&quot;, &quot;ISO-8859-9&quot;, $desc), 15);
}

return $video;
}
</pre>
<p>Öncelikle bu fonksiyonun çalışması için 6. satırdaki xml2array() fonksiyonunun da kodlarınız arasında olması gerekir. Bu fonksiyon php.net&#8217;ten bulduğum herhangi bir XML&#8217;i PHP arraya dönüştüren fonksiyondan birisi. Bu fonksiyonu diğer XML veriler için de kullanabilirsiniz.<span id="more-5453"></span></p>
<pre class="brush: php;">

    function xml2array($url, $get_attributes = 1, $priority = 'tag')
    {
        $contents = &quot;&quot;;
        if (!function_exists('xml_parser_create'))
        {
            return array ();
        }
        $parser = xml_parser_create('');
        if (!($fp = @ fopen($url, 'rb')))
        {
            return array ();
        }
        while (!feof($fp))
        {
            $contents .= fread($fp, 8192);
        }
        fclose($fp);
        xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, &quot;UTF-8&quot;);
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
        xml_parse_into_struct($parser, trim($contents), $xml_values);
        xml_parser_free($parser);
        if (!$xml_values)
            return; //Hmm...
        $xml_array = array ();
        $parents = array ();
        $opened_tags = array ();
        $arr = array ();
        $current = &amp; $xml_array;
        $repeated_tag_index = array ();
        foreach ($xml_values as $data)
        {
            unset ($attributes, $value);
            extract($data);
            $result = array ();
            $attributes_data = array ();
            if (isset ($value))
            {
                if ($priority == 'tag')
                    $result = $value;
                else
                    $result['value'] = $value;
            }
            if (isset ($attributes) and $get_attributes)
            {
                foreach ($attributes as $attr =&gt; $val)
                {
                    if ($priority == 'tag')
                        $attributes_data[$attr] = $val;
                    else
                        $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
                }
            }
            if ($type == &quot;open&quot;)
            {
                $parent[$level -1] = &amp; $current;
                if (!is_array($current) or (!in_array($tag, array_keys($current))))
                {
                    $current[$tag] = $result;
                    if ($attributes_data)
                        $current[$tag . '_attr'] = $attributes_data;
                    $repeated_tag_index[$tag . '_' . $level] = 1;
                    $current = &amp; $current[$tag];
                }
                else
                {
                    if (isset ($current[$tag][0]))
                    {
                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
                        $repeated_tag_index[$tag . '_' . $level]++;
                    }
                    else
                    {
                        $current[$tag] = array (
                            $current[$tag],
                            $result
                        );
                        $repeated_tag_index[$tag . '_' . $level] = 2;
                        if (isset ($current[$tag . '_attr']))
                        {
                            $current[$tag]['0_attr'] = $current[$tag . '_attr'];
                            unset ($current[$tag . '_attr']);
                        }
                    }
                    $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
                    $current = &amp; $current[$tag][$last_item_index];
                }
            }
            elseif ($type == &quot;complete&quot;)
            {
                if (!isset ($current[$tag]))
                {
                    $current[$tag] = $result;
                    $repeated_tag_index[$tag . '_' . $level] = 1;
                    if ($priority == 'tag' and $attributes_data)
                        $current[$tag . '_attr'] = $attributes_data;
                }
                else
                {
                    if (isset ($current[$tag][0]) and is_array($current[$tag]))
                    {
                        $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
                        if ($priority == 'tag' and $get_attributes and $attributes_data)
                        {
                            $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
                        }
                        $repeated_tag_index[$tag . '_' . $level]++;
                    }
                    else
                    {
                        $current[$tag] = array (
                            $current[$tag],
                            $result
                        );
                        $repeated_tag_index[$tag . '_' . $level] = 1;
                        if ($priority == 'tag' and $get_attributes)
                        {
                            if (isset ($current[$tag . '_attr']))
                            {
                                $current[$tag]['0_attr'] = $current[$tag . '_attr'];
                                unset ($current[$tag . '_attr']);
                            }
                            if ($attributes_data)
                            {
                                $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
                            }
                        }
                        $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
                    }
                }
            }
            elseif ($type == 'close')
            {
                $current = &amp; $parent[$level -1];
            }
        }
        return ($xml_array);
    }
</pre>
<p>Bundan sonra kendi kodlarınız içinde youtubeParse() fonksiyonunu çağırıp bir değişkene atadığınızda, o array değişkeninin içeriğini kullanarak amacınıza ulaşmış olursunuz.</p>
<pre class="brush: php;">
$result = youtubeParse(&quot;http://www.youtube.com/watch?v=0peX66dC6Sk&quot;);
if ( $result['works'] == &quot;NO&quot; )
echo &quot;Video bulunamadı&quot;;
else
{
//videonun başlığı
echo $result['title'];

//videonun açıklaması, türkçe karaktere göre düzenlenmiştir
echo $result['desc'];

//videonun resmi
echo $result['img'];
}
</pre>
<p><strong>Fonksiyonda YouTube videosunun resmini alırken 1.jpg&#8217;yi kullandık. Eğer alternatif resimleri almak istiyorsanız, 0.jpg, 1.jpg, 3.jpg&#8217;yi deneyebilirsiniz. 0.jpg büyük resim olup 1., 2. ve 3. resimler küçük alternatif resimlerdir.</strong></p>
<p>Temel olarak yaptığımız şey, her videoya ait RSS beslemesine girip oradaki bilgileri işimize yarayacak şekilde elemek oldu(parse).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ekimdusu.net/index.php/2009/12/27/php-ile-youtubeden-video-ile-ilgili-bilgi-alma/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP&#8217;de strip_tag fonksiyonu</title>
		<link>http://www.ekimdusu.net/index.php/2009/11/19/aspde-strip_tag-fonksiyonu/</link>
		<comments>http://www.ekimdusu.net/index.php/2009/11/19/aspde-strip_tag-fonksiyonu/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 13:21:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bilgisayar]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[fonksiyon]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[strip tag]]></category>
		<category><![CDATA[strip_tag]]></category>

		<guid isPermaLink="false">http://blog.cagdaspolat.com/?p=911</guid>
		<description><![CDATA[Sürekli PHP&#8217;de kod yazinca insan PHP fonksiyonlarina asina oluyor. Tabi ondan sonra dönüp ASP kod yazmasi gerektigi zaman durum oldukça kötü oluyor. 2009 yilinda insanlar neden hala ASP ile kod yaziyor demeyin. Insanin hala ihtiyaci olabiliyor. Asp.NET ile site hazirlamak daha kolay olabilir ama daha masrafli. Sonuç olarak sitede haberleri gösterirken, veritabaninda HTML olarak sakladigim [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" title="Resmin strip_tagla bir alakası yok, renk olsun diye ekledim.." src="http://www.dijksterhuis.org/wp-content/uploads/2009/03/sub.jpg" alt="" width="500" height="205" /></p>
<p>Sürekli PHP&#8217;de kod yazinca insan PHP fonksiyonlarina asina oluyor. Tabi ondan sonra dönüp ASP kod yazmasi gerektigi zaman durum oldukça kötü oluyor. 2009 yilinda insanlar neden hala ASP ile kod yaziyor demeyin. Insanin hala ihtiyaci olabiliyor. Asp.NET ile site hazirlamak daha kolay olabilir ama daha masrafli. Sonuç olarak sitede haberleri gösterirken, veritabaninda HTML olarak sakladigim metni etiketlerinden(taglarindan) ayirmam gerekti. Bunu PHP&#8217;de strip_tag fonksiyonuyla yapiyorduk ancak eski usül ASP&#8217;de karsiligini bulamadim. Ama internette su kodu buldum, umarim isinize yarar.</p>
<pre class="brush: vb;">
function strip_tags(unsafeString)
dim regEx

set regEx = new RegExp
with regEx
.Global = true
.IgnoreCase = true
.Pattern = &amp;quot;(\&amp;lt;(/?[^\&amp;gt;]+)\&amp;gt;)&amp;quot;
end with
strip_tags = regEx.Replace(unsafeString, &amp;quot;&amp;quot;)
set regEx = nothing
end function
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ekimdusu.net/index.php/2009/11/19/aspde-strip_tag-fonksiyonu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
