<?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>TSQL - Transact SQL - C#, PHP, Visual Basic, C++</title>
	<atom:link href="http://www.tsql.de/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tsql.de</link>
	<description>TSQL Transact SQL und SQL in Verbindung mit Progammiersprachen wie c#,csharp,c++,cplusplus,visual basic, vb, php.</description>
	<lastBuildDate>Sun, 06 Nov 2011 15:29:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP Reguläre Ausdrücke, REGEX oder PREG</title>
		<link>http://www.tsql.de/php/php_preg_regex_regulaerer_ausdruck</link>
		<comments>http://www.tsql.de/php/php_preg_regex_regulaerer_ausdruck#comments</comments>
		<pubDate>Wed, 16 Feb 2011 20:40:22 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[preg]]></category>
		<category><![CDATA[reguläre ausdrücke]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1749</guid>
		<description><![CDATA[Reguläre Ausdrücke sind für viele ein rotes Tuch. In diesem Tipp habe ich daher einige Regex gesammelt. Überschrift einer Webseite ermitteln. Telefonnummer prüfen. Wiederholende Leerzeichen ersetzen. IP Adresse prüfen. Datumsangaben aus ein Text filtern]]></description>
			<content:encoded><![CDATA[<p>Reguläre Ausdrücke sind für viele ein rotes Tuch. In diesem Tipp habe ich daher einige Regex gesammelt. In PHP stehen mehrere Funktionen zur Verfügung, die mit regulären Ausdrücken &#8220;gefüttert&#8221; werden können. Hier eine kleine Übersicht:</p>
<table>
<tr>
<th>Funktion</th>
<th>Beschreibung</th>
</tr>
<tr>
<td>preg_filter</td>
<td>Sucht und ersetzt mit regulären Ausdrücken</td>
</tr>
<tr>
<td>preg_grep</td>
<td>Liefert Array-Elemente, die auf ein Suchmuster passen</td>
</tr>
<tr>
<td>preg_replace_callback</td>
<td>Sucht und ersetzt einen regulären Ausdruck unter Verwendung eines Callbacks</td>
</tr>
<tr>
<td>preg_match_all</td>
<td>Führt eine umfassende Suche nach Übereinstimmungen mit regulärem Ausdruck durch</td>
</tr>
<tr>
<td>preg_match</td>
<td>Führt eine Suche mit einem regulären Ausdruck durch</td>
</tr>
<tr>
<td>preg_replace</td>
<td>Sucht und ersetzt mit regulären Ausdrücken</td>
</tr>
<tr>
<td>preg_split</td>
<td>Zerlegt eine Zeichenkette anhand eines regulären Ausdrucks</td>
</tr>
<tr>
<td>preg_quote</td>
<td>Maskiert Zeichen regulärer Ausdrücke</td>
</tr>
</table>
<p>Als nächsten sehen wir einige einfache reguläre Ausdrücke und deren Bedeutung. Die Muster werden immer von einem Begrenzungszeichen (Delimiter) eingeschlossen. Bei der Auswahl des Delimiters ist darauf zu achten, dass dieses Zeichen nicht innerhalb des Musters vorkommt.<br />
Eine kleine Übersicht über Suchmuster:</p>
<table>
<tr>
<th>Regulärer Ausdruck (Pattern)</th>
<th>Sucht nach .. </th>
</tr>
<tr>
<td>[a-z]</td>
<td>einzelner Kleinbuchstabe</td>
</tr>
<tr>
<td>[A-Z]</td>
<td>einzelner Großbuchstabe</td>
</tr>
<tr>
<td>hallo</td>
<td>der String &#8220;hallo&#8221; wird gesucht</td>
</tr>
<tr>
<td>[a-z]+</td>
<td>ein oder mehrere Kleinbuchstaben</td>
</tr>
<tr>
<td>[g-z]</td>
<td>ein einzelner Kleinbuchstabe zwischen &#8220;g&#8221; und &#8220;z&#8221;</td>
</tr>
<tr>
<td>[abc]</td>
<td>die Kleinbuchstaben &#8220;a&#8221;, &#8220;b&#8221; und &#8220;c&#8221;</td>
</tr>
<tr>
<td>[a-zA-Z]</td>
<td>ein einzelner Buchstabe</td>
</tr>
<tr>
<td>[^a-z]</td>
<td>Sucht nach einem beliebigen Zeichen, welches kein Kleinbuchstabe ist.</td>
</tr>
<tr>
<td>[0-9]</td>
<td>eine einzelne Zahl</td>
</tr>
<tr>
<td>[0-4a-d]+</td>
<td>jede Zahl zwischen &#8220;0&#8243; und &#8220;4&#8243; und jeden Kleinbuchstaben zwischen &#8220;a&#8221; und &#8220;d&#8221;</td>
</tr>
<tr>
<td>(hallo|welt)</td>
<td>die Wörter &#8220;hallo&#8221; und &#8220;welt&#8221;</td>
</tr>
<tr>
<td>[a-z]{3,5}</td>
<td>mindestens drei und maximal fünf Kleinbuchstaben zwischen &#8220;a&#8221; und &#8220;z&#8221;</td>
</tr>
</table>
<p>Und jetzt einige Praxisbeispiel:</p>
<h4>Den Inhalt der H1 Überschrift einer Webseite ermitteln</h4>

<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;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;PHP REGEX&lt;/h1&gt;&lt;h2&gt;Beispiel&lt;/h2&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'~&lt;h1&gt;(.+?)&lt;/h1&gt;~is'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$matches</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: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Den Inhalt aller Überschrift einer Webseite ermitteln</h4>
<p>Der Inhalt der Überschriften befindet sich in $matches[2].</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;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;PHP REGEX&lt;/h1&gt;&lt;h2&gt;Beispiel&lt;/h2&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'~&lt;h([1-6])&gt;(.+?)&lt;/h\1&gt;~is'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Telefonnummer prüfen</h4>
<p>Hier wird nur geprüft ob es sich um eine Zahlenfolge handelt. Ein Plus vor der Telefonnummer ist optional.</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;">$nummer</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;+4937512345678&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^[+]?[0-9]+$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nummer</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;korrekt!&quot;</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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;nicht korrekt!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Wiederholende Leerzeichen ersetzen </h4>

<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;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PHP REGEX         Test Text.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[ ]{2,}/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>IP Adresse prüfen</h4>
<p>Eine IP Adresse besteht aus vier Blöcken, welche jeweils mit einem Punkt voneinander getrennt sind. Jeder einzelne Block kann im Bereich von 0 &#8211; 255 liegen. Mal abgesehen von einigen speziellen Adressen, welche ich nicht berücksichtigt habe, prüft folgendes Regex eine IP Adresse auf Gültigkeit. Spezielle Adresse sind z.B. Broadcast, Zeroconf, Anycast oder Multicast.</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;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;192.168.12.203&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^(([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.){3}([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;korrekt!&quot;</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: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;nicht korrekt!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Datumsangaben aus ein Text filtern</h4>

<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;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Was war noch gleich am 24.12.2010 und was am 1.1.99&quot;</span><span style="color: #339933;">;</span>  
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/([012]?[0-9]|3[01])\.(0?[0-9]|1[0-2])\.(([12][0-9])?[0-9][0-9])/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</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: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/php/php_preg_regex_regulaerer_ausdruck/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Hashfunktion MD5 und SHA1</title>
		<link>http://www.tsql.de/csharp/csharp_md5_sha1_hash</link>
		<comments>http://www.tsql.de/csharp/csharp_md5_sha1_hash#comments</comments>
		<pubDate>Sun, 13 Feb 2011 13:42:32 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[sha1]]></category>
		<category><![CDATA[System.Security.Cryptography]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1741</guid>
		<description><![CDATA[C# MD5 Hash und SHA1 Hash berechnen.]]></description>
			<content:encoded><![CDATA[<p>Zur Berechnung des MD5 und des SHA1 Hashes in C# bedient man sich des &#8220;System.Security.Cryptography&#8221; Namespaces.</p>
<p>Quellcode C# MD5:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Liefert den MD5 Hash </span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;input&quot;&gt;Eingabestring&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;MD5 Hash der Eingabestrings&lt;/returns&gt;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> getMD5<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> input<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">//Umwandlung des Eingastring in den MD5 Hash</span>
    <span style="color: #000000;">System.<span style="color: #0000FF;">Security</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cryptography</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">MD5</span> md5 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Security</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cryptography</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">MD5CryptoServiceProvider</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> textToHash <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>input<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> result <span style="color: #008000;">=</span> md5<span style="color: #008000;">.</span><span style="color: #0000FF;">ComputeHash</span><span style="color: #008000;">&#40;</span>textToHash<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">//MD5 Hash in String konvertieren</span>
    <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">StringBuilder</span> s <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">StringBuilder</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span> b <span style="color: #0600FF; font-weight: bold;">in</span> result<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        s<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>b<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;x2&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Quellcode C# SHA1:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Liefert den SHA1 Hash </span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;input&quot;&gt;Eingabestring&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;SHA1 Hash der Eingabestrings&lt;/returns&gt;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> getSHA1<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> input<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">//Umwandlung des Eingastring in den SHA1 Hash</span>
    <span style="color: #000000;">System.<span style="color: #0000FF;">Security</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cryptography</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">SHA1</span> sha1 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Security</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cryptography</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">SHA1CryptoServiceProvider</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> textToHash <span style="color: #008000;">=</span> Encoding<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>input<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> result <span style="color: #008000;">=</span> sha1<span style="color: #008000;">.</span><span style="color: #0000FF;">ComputeHash</span><span style="color: #008000;">&#40;</span>textToHash<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">//SHA1 Hash in String konvertieren</span>
    <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">StringBuilder</span> s <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Text</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">StringBuilder</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span> b <span style="color: #0600FF; font-weight: bold;">in</span> result<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        s<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>b<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;x2&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Grundlegend sind die beiden Methoden gleich.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/csharp/csharp_md5_sha1_hash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Switch</title>
		<link>http://www.tsql.de/php/php_switch_case</link>
		<comments>http://www.tsql.de/php/php_switch_case#comments</comments>
		<pubDate>Fri, 11 Feb 2011 19:32:13 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1732</guid>
		<description><![CDATA[PHP switch case Anweisung. Beispiele für die Verwendung. Fallunterscheidung in PHP mit switch, case und default.]]></description>
			<content:encoded><![CDATA[<p>Zur Fallunterscheidung in PHP bietet sich die &#8220;switch case&#8221; Anweisung geradezu an.  Zu beachten ist bei PHP, dass die einzelnen Cases, also die Fälle mit einem break abgeschlossen werden müssen. Ist das break nicht vorhanden werden alle weiteren Cases bis zum nächsten break auch mit ausgeführt. Dieses Verhalten kann von Vorteil sein, man muss es nur kennen.<br />
Sollte kein Fall zutreffen wird wenn vorhanden der default-case abgearbeitet.<br />
&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Fall A&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;B&quot;</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Fall B&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Standard Fall&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Wenn der selbe Code für mehrere Fälle gültig ist, muss das break Schlüsselwort fehlen.<br />
&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;B&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #339933;">:</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;B&quot;</span><span style="color: #339933;">:</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;C&quot;</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Fall A-C&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;D&quot;</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Fall D&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Standard Fall&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/php/php_switch_case/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Array zufällig sortieren</title>
		<link>http://www.tsql.de/php/php_array_shuffle_sortieren_zufall</link>
		<comments>http://www.tsql.de/php/php_array_shuffle_sortieren_zufall#comments</comments>
		<pubDate>Fri, 11 Feb 2011 16:57:36 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[zufall]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1725</guid>
		<description><![CDATA[Die Reihenfolge aller Elemente eines Arrays zufällig neu sortieren und anschließend ausgeben.]]></description>
			<content:encoded><![CDATA[<p>Die Reihenfolge aller Elemente eines Arrays zufällig neu sortieren und anschließend ausgeben. Hier ist die Lösung:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">//dem Zufall auf die Sprünge helfen</span>
	<span style="color: #990000;">srand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//array anlegen</span>
	<span style="color: #000088;">$karten</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Bube'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Dame'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'König'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//zufällig michen</span>
	<span style="color: #990000;">shuffle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$karten</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//array ausgeben</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$karten</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$karte</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$karte</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/php/php_array_shuffle_sortieren_zufall/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# INI File lesen</title>
		<link>http://www.tsql.de/csharp/csharp-ini-file-lesen</link>
		<comments>http://www.tsql.de/csharp/csharp-ini-file-lesen#comments</comments>
		<pubDate>Fri, 19 Nov 2010 16:32:47 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[ini]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1702</guid>
		<description><![CDATA[Auslesen einer INI-Datei mit CSharp.]]></description>
			<content:encoded><![CDATA[<p>In diesem Beispiel wird das Auslesen einer INI-Datei gezeigt. Hier erst mal der Inhalt der INI-Datei:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>Option<span style="">&#93;</span></span>
<span style="color: #000099;">Farbe</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">blau</span>
<span style="color: #000099;">Name</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">Hans</span></pre></td></tr></table></div>

<p>Der Quellcode:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Runtime.InteropServices</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;kernel32&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">int</span> GetPrivateProfileString<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> section,
<span style="color: #6666cc; font-weight: bold;">string</span> key, <span style="color: #6666cc; font-weight: bold;">string</span> def, StringBuilder retVal, <span style="color: #6666cc; font-weight: bold;">int</span> size, <span style="color: #6666cc; font-weight: bold;">string</span> filePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetString<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> section, <span style="color: #6666cc; font-weight: bold;">string</span> key<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> size <span style="color: #008000;">=</span> <span style="color: #FF0000;">255</span><span style="color: #008000;">;</span>
      <span style="color: #6666cc; font-weight: bold;">string</span> file <span style="color: #008000;">=</span> Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentDirectory</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>test.INI&quot;</span><span style="color: #008000;">;</span>
      <span style="color: #6666cc; font-weight: bold;">string</span> def <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
      StringBuilder sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span>size<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      GetPrivateProfileString<span style="color: #008000;">&#40;</span>section, key, def, sb, size, file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      <span style="color: #0600FF; font-weight: bold;">return</span> sb<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Auslesen des Schlüssels &#8220;Farbe&#8221; aus der Sektion &#8220;Options&#8221;:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">;</span>
args <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span>GetString<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Options&quot;</span>, <span style="color: #666666;">&quot;Farbe&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/csharp/csharp-ini-file-lesen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# ByteArray-To-Image</title>
		<link>http://www.tsql.de/csharp/c-bytearray-to-image</link>
		<comments>http://www.tsql.de/csharp/c-bytearray-to-image#comments</comments>
		<pubDate>Mon, 15 Nov 2010 21:42:37 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[byteArray]]></category>
		<category><![CDATA[datenbank]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[MemoryStream]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1693</guid>
		<description><![CDATA[Konvertiert Bilddaten, die als Bytearray abgelegt wurden in das Imageformat Bitmap oder Metafile]]></description>
			<content:encoded><![CDATA[<p>
Folgende Beispiel-Methode konvertiert Bilddaten, die als Bytearray abgelegt wurden in das Imageformat Bitmap oder Metafile. Kann in Verbindung mit der Klasse System.Windows.Forms.PictureBox verwendet werden.
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Drawing</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Image</span> ByteArrayToImage<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> byteArray<span style="color: #008000;">&#41;</span> 
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">try</span>
      <span style="color: #008000;">&#123;</span>
      	<span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">MemoryStream</span> ms <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">MemoryStream</span><span style="color: #008000;">&#40;</span>
                                                          byteArray, <span style="color: #FF0000;">0</span>, 
                                                          byteArray<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        ms<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>byteArray, <span style="color: #FF0000;">0</span>, byteArray<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Drawing</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Image</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FromStream</span><span style="color: #008000;">&#40;</span>ms, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">catch</span>
      <span style="color: #008000;">&#123;</span>                
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>            
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/csharp/c-bytearray-to-image/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Funktion &#8220;range&#8221;</title>
		<link>http://www.tsql.de/php/php-range</link>
		<comments>http://www.tsql.de/php/php-range#comments</comments>
		<pubDate>Thu, 30 Sep 2010 19:49:32 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[range]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1676</guid>
		<description><![CDATA[Alle Zahlen von 0-100 ausgeben ist relativ einfach. Sollen aber z.B. alle Buchstaben von "g" bis "z" angezeigt oder "hochgezählt" werden, ist das schon kniffliger.]]></description>
			<content:encoded><![CDATA[<p>Alle Zahlen von 0-100 ausgeben ist relativ einfach. Sollen aber z.B. alle Buchstaben von &#8220;g&#8221; bis &#8220;z&#8221; angezeigt oder &#8220;hochgezählt&#8221; werden, ist das schon kniffliger. Eigentlich sind aber beide Problemstellungen gleich und können bequem mit der PHP Funktion &#8220;range&#8221; gelöst werden. Die Range-Funktion erstellt ein Array mit allen Elementen vom übergebenen Startelement bis zum Endelement. Das erste Beispiel erzeugt ein Array mit allen Buchstaben von &#8220;a&#8221; bis &#8220;z&#8221; und gibt die Buchstaben einzeln an den Browser aus.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'z'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$buchstabe</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$buchstabe</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Das zweite Beispiel gibt alle Zahlen von 500 bis 1000 in 100 Schritten aus:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$zahl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$zahl</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Oder das Alphabet mal rückwärts ausgeben:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'z'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$buchstabe</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$buchstabe</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Der optionale &#8220;step&#8221; &#8211; Parameter kann auch bei Buchstaben benutzt werden, so ist es auch möglich nur jeder dritten Buchstaben des Alphabets anzuzeigen:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'z'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$buchstabe</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$buchstabe</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/php/php-range/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Cache</title>
		<link>http://www.tsql.de/php/php_cache</link>
		<comments>http://www.tsql.de/php/php_cache#comments</comments>
		<pubDate>Sat, 25 Sep 2010 10:45:52 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1662</guid>
		<description><![CDATA[In diesem Tipp wird ein einfaches Cachesystem mit PHP gebaut. Dabei wird der Seitenoutput als Datei abgelegt ....]]></description>
			<content:encoded><![CDATA[<p>Einfach mal einen Cache implementieren, ist die Zielstellung dieses Tipps. Der hier vorgestellte Cache kann einfach in bestehende Projekte integriert werden und legt die fertig geparste Seite im Dateisystem ab. Beim zweiten Aufruf der Seite liefert das Skript den Inhalt des Cachefiles an den Browser zurück.</p>
<p>Quelltext der Datei <k>cache.php</k>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">//cache verzeichnis definieren</span>
	<span style="color: #000088;">$cachedir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cachedir/'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//cachefile name definieren</span>
	<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CACHFILE'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cachedir</span> <span style="color: #339933;">.</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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;">is_file</span><span style="color: #009900;">&#40;</span>CACHFILE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//cachefile gefunden, an den browser senden und skript beenden</span>
		<span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span>CACHFILE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//cachefile nicht gefunden</span>
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cache_callback&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> cache_callback<span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span>CACHFILE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//cachfile  im dateisystem ablegen</span>
			<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span>CACHFILE<span style="color: #339933;">,</span><span style="color: #000088;">$buffer</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;">//den buffer zur ausgabe an den browser zurückgeben</span>
	  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>
Für jede zu cachende Seite muss folgendes Skript am Anfang des Quellcodes eingebunden werden:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'cache.php'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
Damit das Skript funktionieren kann, muss außerdem ein Verzeichnis &#8220;cachedir&#8221; angelegt werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/php/php_cache/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Hello World</title>
		<link>http://www.tsql.de/php/php_hello_world</link>
		<comments>http://www.tsql.de/php/php_hello_world#comments</comments>
		<pubDate>Fri, 24 Sep 2010 19:26:01 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Hello World]]></category>

		<guid isPermaLink="false">http://www.tsql.de/?p=1655</guid>
		<description><![CDATA[Gehört einfach dazu. Dieser Tipp beschreibt das Skript Hello World in PHP.]]></description>
			<content:encoded><![CDATA[<p>Dieser Tipp beschreibt das Einsteiger Skript Hello World in PHP und erzeugt eine &#8220;Hello World!&#8221; Meldung.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td 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: #0000ff;">'Hello World!'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Hier noch ein Mix von HTML und PHP Code</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;html&gt;
 &lt;head&gt;
&nbsp;
 &lt;/head&gt;
 &lt;body&gt;
&lt;h2&gt;Das erste PHP Skript&lt;/h2&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hello World!'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/php/php_hello_world/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Median berechnen</title>
		<link>http://www.tsql.de/php/median_berechnen_funktion</link>
		<comments>http://www.tsql.de/php/median_berechnen_funktion#comments</comments>
		<pubDate>Sun, 26 Apr 2009 21:11:25 +0000</pubDate>
		<dc:creator>Michael Klaus</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[anatomische Lagebezeichnung]]></category>
		<category><![CDATA[Durchschnitt]]></category>
		<category><![CDATA[median]]></category>
		<category><![CDATA[statistik]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/allgemein/php-median-berechnen</guid>
		<description><![CDATA[Median oder Zentralwert bezeichnet den Mittelwert einer Zahlenreihe.]]></description>
			<content:encoded><![CDATA[<p>Median oder Zentralwert bezeichnet den Mittelwert einer Zahlenreihe. Dabei ist der Median robuster und lässt sich nicht gleich durch einzelne Ausreißer stören.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> median<span style="color: #009900;">&#40;</span><span style="color: #000088;">$zahlen_array</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$anzahl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$zahlen_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$anzahl</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</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: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$zahlen_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$anzahl</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//gerade Anzahl =&gt; der Median ist das arithmetische Mittel der beiden mittleren Zahlen</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$zahlen_array</span><span style="color: #009900;">&#91;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$anzahl</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</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: #000088;">$zahlen_array</span><span style="color: #009900;">&#91;</span> <span style="color: #000088;">$anzahl</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</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: #666666; font-style: italic;">//ungerade Anzahl =&gt; der mittlere Wert ist der Median    </span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$zahlen_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$anzahl</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">echo</span> median<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">101</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">105</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">110</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">114</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">118</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">221</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tsql.de/php/median_berechnen_funktion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

