<?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>Chris im Netz - Software, Hardware, Tutorials und mehr.. &#187; einslive</title> <atom:link href="http://www.christian-pfnuer.de/tag/einslive/feed" rel="self" type="application/rss+xml" /><link>http://www.christian-pfnuer.de</link> <description>In Deutschland unterwegs, im Netz zu Hause</description> <lastBuildDate>Thu, 02 Sep 2010 00:44:25 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.8.6</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>[PHP] Parsen und Filtern einer Radioplaylist</title><link>http://www.christian-pfnuer.de/php-parsen-und-filtern-einer-radioplaylist</link> <comments>http://www.christian-pfnuer.de/php-parsen-und-filtern-einer-radioplaylist#comments</comments> <pubDate>Fri, 01 May 2009 14:19:23 +0000</pubDate> <dc:creator>chris</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Programmierung]]></category> <category><![CDATA[einslive]]></category> <category><![CDATA[filtern]]></category> <category><![CDATA[fopen]]></category> <category><![CDATA[parsen]]></category> <category><![CDATA[regular expressions]]></category> <category><![CDATA[webradio]]></category> <category><![CDATA[webseite]]></category><guid isPermaLink="false">http://christian-pfnuer.de/?p=3</guid> <description><![CDATA[Nachdem ich mir die Zähne an “Regular Expressions” zum filtern eines Datensatzes in php ausgebissen habe, hat mir schließlich jemand den entscheidenden Anstoß gegeben. Mein Ansatz fing damit an, dass ich mir erstmal die Seite via fopen holen wollte:$filestream = fopen&#40;&#34;http://www.einslive.de/multimedia/diggi/&#34;, &#34;r&#34;&#41;;
while&#40;!feof&#40;$filestream&#41;&#41; &#123;
$nowplaying = fgets&#40;$filestream, 500000&#41;;
echo $nowplaying;
&#125;
fclose&#40;$filestream&#41;;Das [...]]]></description> <content:encoded><![CDATA[<p>Nachdem ich mir die Zähne an “Regular Expressions” zum filtern eines Datensatzes in php ausgebissen habe, hat mir schließlich jemand den entscheidenden Anstoß gegeben. Mein Ansatz fing damit an, dass ich mir erstmal die Seite via fopen holen wollte:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$filestream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.einslive.de/multimedia/diggi/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filestream</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$nowplaying</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filestream</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">500000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nowplaying</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filestream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Das hat auch sehr gut funktioniert.Nun kann zwar die Seite geholt werden, es fehlt aber noch das Filtern mit “Regular Expressions”. Ein sehr hilfreiches deutsches Tutorial zu Regular Expressions/RegExp/Reguläre Ausdrücke ist hier zu finden:</p><div id="attachment_4" class="wp-caption aligncenter" style="width: 310px"><a href="http://regexp-evaluator.de/tutorial/"><img class="size-medium wp-image-4" title="regulaereausdruecke" src="http://christian-pfnuer.de/wp-content/uploads/2009/05/regulaereausdruecke-300x165.png" alt="http://regexp-evaluator.de/tutorial/" width="300" height="165" /></a><p class="wp-caption-text">http://regexp-evaluator.de/tutorial/</p></div><p>Der vollständige Code sieht nun folgendermaßen aus:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.einslive.de/multimedia/diggi/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'
]*&amp;gt;(.*?)
&nbsp;
'&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">215</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$treffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'
]*&amp;gt;(.*?)
&nbsp;
'&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$treffer</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ausgabe</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hit</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">' - '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$hit</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Aktuell um '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$hit</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</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: #0000ff;">' auf Einslive Diggi: &lt;strong&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$ausgabe</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/strong&gt;'</span><span style="color: #339933;">;</span></pre></div></div><p>Die Ausgabe dazu kann man sich hier angucken:</p><p><a title="Einslive Diggi - Titelanzeige" href="../docs/php/einslive-parse/final.php" target="_blank">http://christian-pfnuer.de/docs/php/einslive-parse/final.php</a></p><p>Gelernt habe ich in diesem Zusammenhang die Wirkung von Regular Expressions. Wenn ich Zeit und eine schicke Stelle finde wird der Blog vielleicht bald mit meinen zuletzt gehörten Tracks bei Last.fm geschmückt.</p> ]]></content:encoded> <wfw:commentRss>http://www.christian-pfnuer.de/php-parsen-und-filtern-einer-radioplaylist/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>