<?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>simra &#187; Php</title>
	<atom:link href="http://www.simra.ch/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simra.ch</link>
	<description>development &#38; design</description>
	<lastBuildDate>Fri, 26 Mar 2010 15:57:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Highlight Search Words in php</title>
		<link>http://www.simra.ch/2010/02/highlight-search-words-in-php/</link>
		<comments>http://www.simra.ch/2010/02/highlight-search-words-in-php/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 17:30:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[eregi_replace]]></category>
		<category><![CDATA[ereg_replace]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[RegularExpressions]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1102</guid>
		<description><![CDATA[Many sites have opted for highlighting the keywords from their searches. This can be useful for quickly finding relavant words within large pages of text. 
The following php function highlights words within html content (words in tags  are ignored). Here you can find a live demo http://www.newsaddict.ch.

function highlight_html_content &#40;$text, $search&#41;
&#123;
&#160; &#160; $search = eregi_replace&#40;&#34;[^-a-zA-Z0-9üäöÜÄÖèéê&#38;']&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>Many sites have opted for highlighting the keywords from their searches. This can be useful for quickly finding relavant words within large pages of text. </p>
<p>The following php function highlights words within html content (words in tags <> are ignored). Here you can find a live demo <a href="http://www.newsaddict.ch" target="_blank">http://www.newsaddict.ch</a>.<br />
<span id="more-1102"></span></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> highlight_html_content <span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$search</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/eregi_replace"><span style="color: #990000;">eregi_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[^-a-zA-Z0-9üäöÜÄÖèéê&amp;']&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Sonderzeichen entfernen </span><br />
&nbsp; &nbsp; <span style="color: #000088;">$search</span><span style="color: #339933;">=</span> <a href="http://www.php.net/ereg_replace"><span style="color: #990000;">ereg_replace</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[ ]+&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Doppelte Leerzeichen entfernen</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Array mit Wörter erstellen</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$word</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_quote"><span style="color: #990000;">preg_quote</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$word</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$regexp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/(<span style="color: #006699; font-weight: bold;">$w</span>)(?![^&lt;]+&gt;)/iu&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Wörter innerhalb eines Tags werden ignoriert -&gt; i Gross-/Kleinschreibung nicht beachten -&gt; u UTF8 damit ä=Ä ü=Ü...</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$replacement</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;b style=&quot;color:#FF0&quot;&gt;\\1&lt;/b&gt;'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$regexp</span><span style="color: #339933;">,</span><span style="color: #000088;">$replacement</span> <span style="color: #339933;">,</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2010/02/highlight-search-words-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Regular Expression to extract Urls</title>
		<link>http://www.simra.ch/2010/01/php-regular-expression-to-extract-urls/</link>
		<comments>http://www.simra.ch/2010/01/php-regular-expression-to-extract-urls/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 13:17:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[preg_match_all]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[RegularExpressions]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1072</guid>
		<description><![CDATA[The following function extract all links from a page and returns them as an array.

$content = file_get_contents&#40;&#34;http://www.simra.ch&#34;&#41;;
echo var_dump&#40;getLinks&#40; $content &#41;&#41;;

function getLinks&#40;$content&#41; &#123;
&#160; &#160; preg_match_all&#40;'/(href&#124;src)\=(\&#34;&#124;\')[^\&#34;\'\&#62;]+/i',$content,$media&#41;;
&#160; &#160; $array=preg_replace&#40;'/(href&#124;src)(\&#34;&#124;\'&#124;\=\&#34;&#124;\=\')(.*)/i',&#34;$3&#34;,$media&#91;0&#93;&#41;;
&#160; &#160; return $array;
&#125;
]]></description>
			<content:encoded><![CDATA[<p>The following function extract all links from a page and returns them as an array.<br />
<span id="more-1072"></span></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.simra.ch&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span>getLinks<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$content</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> getLinks<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/preg_match_all"><span style="color: #990000;">preg_match_all</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(href|src)\=(\&quot;|\')[^\&quot;\'\&gt;]+/i'</span><span style="color: #339933;">,</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #000088;">$media</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$array</span><span style="color: #339933;">=</span><a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(href|src)(\&quot;|\'|\=\&quot;|\=\')(.*)/i'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$3</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$media</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2010/01/php-regular-expression-to-extract-urls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Regular expression to remove scripts</title>
		<link>http://www.simra.ch/2010/01/php-regular-expression-to-remove-scripts/</link>
		<comments>http://www.simra.ch/2010/01/php-regular-expression-to-remove-scripts/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 12:58:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[RegularExpressions]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1070</guid>
		<description><![CDATA[The following regex removes all script tags.

$content = preg_replace&#40;'#(\n?&#60;script[^&#62;]*?&#62;.*?&#60;/script[^&#62;]*?&#62;)&#124;(\n?&#60;script[^&#62;]*?/&#62;)#is', '', $content&#41;;
]]></description>
			<content:encoded><![CDATA[<p>The following regex removes all script tags.<br />
<span id="more-1070"></span></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#(\n?&lt;script[^&gt;]*?&gt;.*?&lt;/script[^&gt;]*?&gt;)|(\n?&lt;script[^&gt;]*?/&gt;)#is'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2010/01/php-regular-expression-to-remove-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Youtube Video Downloader in PHP</title>
		<link>http://www.simra.ch/2009/12/youtube-video-downloader-in-php/</link>
		<comments>http://www.simra.ch/2009/12/youtube-video-downloader-in-php/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 12:35:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[get_video]]></category>
		<category><![CDATA[video_id]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=885</guid>
		<description><![CDATA[The following Php-Script is able to download videos from youtube in three different formats (MP4 for hight, FLV for medium and 3GP for low quality). In addition the script provides a preview of the current video.

View Demo

Here&#8217;s the source:
&#60;?php
if&#40;isset&#40;$_GET&#91;'u'&#93;&#41;&#41;&#123;
&#160; &#160; $v = urldecode&#40;$_GET&#91;'u'&#93;&#41;;
&#160; &#160; if&#40;$_GET&#91;'fmt'&#93; == 17&#41;&#123; // 3gp
&#160; &#160; &#160; &#160; header&#40;&#34;Content-Type: video/3gp&#34;&#41;; &#160;
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>The following Php-Script is able to download videos from youtube in three different formats (MP4 for hight, FLV for medium and 3GP for low quality). In addition the script provides a preview of the current video.</p>
<p><a href="http://onyou.ch/services/?service=youtube_downloader.php" target="_blank"><br />
View Demo</a></p>
<p><span id="more-885"></span><br />
Here&#8217;s the source:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/urldecode"><span style="color: #990000;">urldecode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fmt'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">17</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// 3gp</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: video/3gp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span>video.3gp<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$v</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;&amp;amp;fmt=17&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fmt'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">18</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// mp4</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: video/mp4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span>video.mp4<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$v</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;&amp;amp;fmt=18&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// flv</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: video/x-flv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span>video.flv<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/readfile"><span style="color: #990000;">readfile</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/flush"><span style="color: #990000;">flush</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$yu</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.youtube.com/watch?v=qGyfaoUAWtM'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;yu&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$yu</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;yu&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yu</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&quot;video_id&quot;: &quot;(.*?)&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&quot;t&quot;: &quot;(.*?)&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #000088;">$m1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$t</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #000088;">$m1</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$u</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.youtube.com/get_video?video_id=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;t=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$t</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&lt;h1&gt;Youtube Url:&lt;/h1&gt;<br />
&lt;form method=&quot;get&quot; id=&quot;form&quot; onSubmit=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<br />
&lt;input type=&quot;text&quot; name=&quot;yu&quot; id=&quot;yu&quot; size=&quot;80&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$yu</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt; &lt;input type=&quot;submit&quot; name=&quot;b&quot; id=&quot;b&quot; value=&quot;Load&quot; /&gt;<br />
&lt;/form&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&lt;h1&gt;Prewiew:&lt;/h1&gt;<br />
&lt;img src=&quot;http://img.youtube.com/vi/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$id</span><span style="color: #000000; font-weight: bold;">?&gt;</span>/1.jpg&quot; alt=&quot;Preview 1&quot; /&gt;<br />
&lt;img src=&quot;http://img.youtube.com/vi/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$id</span><span style="color: #000000; font-weight: bold;">?&gt;</span>/2.jpg&quot; alt=&quot;Preview 2&quot; /&gt;<br />
&lt;img src=&quot;http://img.youtube.com/vi/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$id</span><span style="color: #000000; font-weight: bold;">?&gt;</span>/3.jpg&quot; alt=&quot;Preview 3&quot; /&gt;<br />
<br />
&lt;h1&gt;Downloads:&lt;/h1&gt;<br />
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?u='</span><span style="color: #339933;">.</span><a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Download FLV&lt;/a&gt;&lt;br /&gt;<br />
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?fmt=18&amp;u='</span><span style="color: #339933;">.</span><a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Download MP4&lt;/a&gt;&lt;br /&gt;<br />
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?fmt=17&amp;u='</span><span style="color: #339933;">.</span><a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Download 3GP&lt;/a&gt;<br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>Please check out my <a href="http://www.simra.ch/2009/12/youtube-video-downloader-in-python/">Youtube Video Downloader in Python</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/12/youtube-video-downloader-in-php/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Simplify a path/url in Php</title>
		<link>http://www.simra.ch/2009/11/simplify-a-path-in-php/</link>
		<comments>http://www.simra.ch/2009/11/simplify-a-path-in-php/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 18:26:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[basename]]></category>
		<category><![CDATA[dirname]]></category>
		<category><![CDATA[pathinfo]]></category>
		<category><![CDATA[realpath]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=708</guid>
		<description><![CDATA[Here&#8217;s a little Php function that simplifies dirs like  /./dir or  dir/../../dir/ and returns a canonicalized pathname. Unlike the function realpath() it works with every path and url and doesn&#8217;t return the absolute path.

function SimplifyPath&#40;$path&#41; &#123;
&#160; &#160; $dirs = explode&#40;'/',$path&#41;;
&#160; &#160; for&#40;$i=0; $i&#60;count&#40;$dirs&#41;;$i++&#41; &#123;
&#160; &#160; &#160; &#160; if&#40;$dirs&#91;$i&#93;==&#34;.&#34; &#124;&#124; $dirs&#91;$i&#93;==&#34;&#34;&#41; &#123;
&#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little Php function that simplifies dirs like  <em>/./dir</em> or  <em>dir/../../dir/</em> and returns a canonicalized pathname. Unlike the function realpath() it works with every path and url and doesn&#8217;t return the absolute path.<br />
<span id="more-708"></span></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> SimplifyPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$dirs</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$dirs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</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: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array_splice"><span style="color: #990000;">array_splice</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$i</span><span style="color: #339933;">--;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</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: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dirs</span><span style="color: #339933;">=</span>Simplify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$i</span><span style="color: #339933;">-=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$dirs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> Simplify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idx</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idx</span><span style="color: #339933;">==</span>0<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$dirs</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$idx</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</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> Simplify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idx</span><span style="color: #339933;">-</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> &nbsp;<a href="http://www.php.net/array_splice"><span style="color: #990000;">array_splice</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirs</span><span style="color: #339933;">,</span><span style="color: #000088;">$idx</span><span style="color: #339933;">-</span>1<span style="color: #339933;">,</span>2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$dirs</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/11/simplify-a-path-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>simplexml_load_string() error when loading XML content from Twitter</title>
		<link>http://www.simra.ch/2009/09/simplexml_load_string-error-when-loading-xml-content-from-twitter/</link>
		<comments>http://www.simra.ch/2009/09/simplexml_load_string-error-when-loading-xml-content-from-twitter/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 01:25:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://blog.simra.ch/?p=337</guid>
		<description><![CDATA[If you are constantly receiving the following error when trying to run simplexml_load_string() to get XML content from Twitter or other, load the xml via file_get_contents() instead of directly into a SimpleXML object (see my example below).
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 10: parser error : Opening and ending tag mismatch: META line 8 and HEAD in/home/vhosts/5000135504/simra.ch/htdocs/simra_2/widgets/twitter.phpon [...]]]></description>
			<content:encoded><![CDATA[<p>If you are constantly receiving the following error when trying to run simplexml_load_string() to get XML content from Twitter or other, load the xml via file_get_contents() instead of directly into a SimpleXML object (see my example below).</p>
<pre>Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 10: parser error : Opening and ending tag mismatch: META line 8 and HEAD in/home/vhosts/5000135504/simra.ch/htdocs/simra_2/widgets/twitter.phpon line 17
Warning: simplexml_load_string() [function.simplexml-load-string]: &lt;/HEAD&gt; in/home/vhosts/5000135504/simra.ch/htdocs/simra_2/widgets/twitter.phpon line 17
Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in/home/vhosts/5000135504/simra.ch/htdocs/simra_2/widgets/twitter.phpon line 17
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 11: parser error : Opening and ending tag mismatch: P line 11 and BODY in/home/vhosts/5000135504/simra.ch/htdocs/simra_2/widgets/twitter.phpon line 17
and so on....</pre>
<pre><span id="more-337"></span></pre>
<pre class="brush: php;">&lt;?php
$feed = file_get_contents("http://twitter.com/statuses/user_timeline/55789790.rss");
$feed = iconv("UTF-8","UTF-8//IGNORE",$feed);
$feedData = simplexml_load_string($feed);

foreach ($feedData-&gt;channel as $channels) {
  echo '&lt;ul&gt;';
  $c=0;
  foreach($channels-&gt;item as $entry)  	{
    echo "&lt;li style='border-bottom: 1px dotted #D2E8F7;margin-bottom:15px;list-style: none;'&gt;$entry-&gt;title";
    echo "&lt;br /&gt;&lt;p align='right' style='color:#848484;font-size:9px;'&gt;".date('d.m.y H:i:s', strtotime($entry-&gt;pubDate))."&lt;/p&gt;";
    echo "&lt;/li&gt;";
    $c++;
    if($c==4){
      break;
    }
  }
  echo "&lt;/ul&gt;";
}
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/09/simplexml_load_string-error-when-loading-xml-content-from-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
