<?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>Stefan Fischerländer's Blog &#187; PHP</title>
	<atom:link href="http://www.fischerlaender.net/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fischerlaender.net</link>
	<description>One Blog Is Not Enough</description>
	<lastBuildDate>Wed, 16 Jun 2010 10:28:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP Kalenderwoche: Kein Bug, nur miese Dokumentation</title>
		<link>http://www.fischerlaender.net/php/php-kalenderwoche-kein-bug-nur-miese-dokumentation</link>
		<comments>http://www.fischerlaender.net/php/php-kalenderwoche-kein-bug-nur-miese-dokumentation#comments</comments>
		<pubDate>Fri, 30 Jan 2009 13:53:12 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/php-kalenderwoche-kein-bug-nur-miese-dokumentation</guid>
		<description><![CDATA[Die PHP date()-Funktion ist ein wunderbares Tool, um mit Datumsangaben zu rechnen. Für ein Projekt brauchte ich nun eine Funktionalität, die mir zu einem Datum Jahr und Kalenderwoche in der Form &#8220;YYYY-WW&#8221; ausgibt. Eigentlich alles ganz einfach mit date() &#8211; &#8220;Y&#8221; steht für die vierstellige Jahreszahl, &#8220;W&#8221; für die zweistellige Kalenderwoche entsprechend der ISO-Definition. Und [...]]]></description>
			<content:encoded><![CDATA[<p>Die PHP date()-Funktion ist ein wunderbares Tool, um mit Datumsangaben zu rechnen. Für ein Projekt brauchte ich nun eine Funktionalität, die mir zu einem Datum Jahr und Kalenderwoche in der Form &#8220;YYYY-WW&#8221; ausgibt. Eigentlich alles ganz einfach mit date() &#8211; &#8220;Y&#8221; steht für die vierstellige Jahreszahl, &#8220;W&#8221; für die zweistellige Kalenderwoche entsprechend der ISO-Definition. Und entsprechend funktioniert das auch:<br />
<code>&gt;&gt;&gt; date("Y-W", strtotime("2006-12-31"))<br />
'2006-52'</code></p>
<p>Doch was passiert, wenn das Jahresende bereits zur Kalenderwoche des neuen Jahres gehört, wie etwa beim Jahreswechsel 2008 auf 2009:<br />
<code>&gt;&gt;&gt; date("Y-W", strtotime("2008-12-31"))<br />
'2008-01'</code></p>
<p>Stimmt nicht ganz, denn der 31.12.2008 liegt nicht in der ersten Kalenderwoche des Jahres 2008, sondern in der 1. KW 2009. Leider zeigte mir die PHP-Dokumentation keinen Hinweis auf das Problem &#8211; was daran lag, dass ich die deutsche Dokumentation hatte. In der englischen Beschreibung findet sich das Format &#8220;o&#8221; (&#8220;kleines Oh&#8221;), das die Jahreszahl nach der selben ISO-Norm wie die Kalenderwoche angibt.<br />
<code>&gt;&gt;&gt; date("o-W", strtotime("2008-12-31"))<br />
'2009-01'</code></p>
<p>Und siehe da, die Ausgabe ist nun wie erwartet. Das Format &#8220;o&#8221; wurde übrigens erst mit PHP 5.1.0 eingeführt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/php/php-kalenderwoche-kein-bug-nur-miese-dokumentation/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PDO, MySQL and Nested Queries</title>
		<link>http://www.fischerlaender.net/php/pdo-mysql-and-nested-queries</link>
		<comments>http://www.fischerlaender.net/php/pdo-mysql-and-nested-queries#comments</comments>
		<pubDate>Wed, 29 Oct 2008 10:19:02 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/pdo-mysql-and-nested-queries</guid>
		<description><![CDATA[PDO (PHP Data Objects) is regarded as state-of-the-art for database access in PHP. But as useful as an abstraction layer may be, the usage of PDO can really be painful. Why? In default mode, PDO uses unbuffered queries to access MySQL. This results in a somewhat strange behaviour: You cannot use two result statements at [...]]]></description>
			<content:encoded><![CDATA[<p>PDO (PHP Data Objects) is regarded as state-of-the-art for database access in PHP. But as useful as an abstraction layer may be, the usage of PDO can really be painful. Why? In default mode, PDO uses unbuffered queries to access MySQL. This results in a somewhat strange behaviour: You cannot use two result statements at the same time on the same database connection. (<a href="http://www.procata.com/blog/archives/2006/12/26/pdo-versus-mdb2/">see an example</a>)</p>
<p>The official solution for this problem is to empty the result set of a previous query using <code>fetchAll()</code>. If you have to process every row in a table, this method copies the entire table into a PHP array. This is fine for small tables. But in a recent project, there&#8217;s one table which is 8 GB large. I surely don&#8217;t want to copy this table into my memory &#8230;</p>
<p>Thanks to <a href="http://ilia.ws/archives/53-PDO_MySQL-Buffered-Query-Support.html">Ilia</a>, there is a solution for this: Just tell the underlying MySQL driver to use buffered queries.</p>
<blockquote><p><code>$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);</code></p></blockquote>
<p>The downside of this approach is obvious: Our PDO-based database access is no longer portable as we now use a MySQL specific functionality. But as long as there is no other solutions for iterating over big tables and issuing a query for every row, I think this is the way to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/php/pdo-mysql-and-nested-queries/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Different strtotime() behaviour in PHP 4 and PHP 5</title>
		<link>http://www.fischerlaender.net/php/different-strtotime-behaviour-in-php-4-and-php-5</link>
		<comments>http://www.fischerlaender.net/php/different-strtotime-behaviour-in-php-4-and-php-5#comments</comments>
		<pubDate>Mon, 31 Mar 2008 17:08:45 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/different-strtotime-behaviour-in-php-4-and-php-5</guid>
		<description><![CDATA[I just wasted about an hour of my working time looking for an error in my code. I tried to use the built-in strtotime() function to convert a date string from a log file to the appropriate timestamp: The date string looks like this: 1/Jan/2007:08:03:50 +0100 Using phpa, the command line PHP tool, I got [...]]]></description>
			<content:encoded><![CDATA[<p>I just wasted about an hour of my working time looking for an error in my code. I tried to use the built-in strtotime() function to convert a date string from a log file to the appropriate timestamp:</p>
<p>The date string looks like this: <code>1/Jan/2007:08:03:50 +0100</code><br />
Using phpa, the command line PHP tool, I got what I expected:<br />
<code>PHP 5.2.0 (cli) (???) [Darwin]<br />
>>> print strtotime("1/Jan/2007:08:03:50 +0100");<br />
1167635030</code></p>
<p>But in my PHP script, the very same command returns -1. After a lot of experiments, I found the problem. While my phpa tool uses PHP5, the script is invoked via php &#8211; which defaults to PHP 4.4.7. Obviously, the date format used in log files was added to strtotime() in PHP5:<br />
<code>macbook:~ sf$ php -r 'print phpversion()."\n"; print strtotime("01/Jan/2007:08:03:50 +0100")."\n";'<br />
4.4.7<br />
-1<br />
macbook:~ sf$ php5 -r 'print phpversion()."\n"; print strtotime("01/Jan/2007:08:03:50 +0100")."\n";'<br />
5.2.0<br />
1167635030</code></p>
<p>So, be sure to check what PHP version you&#8217;re running, if you get into trouble with strtotime().</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/php/different-strtotime-behaviour-in-php-4-and-php-5/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Die Kampagne zur PHP-Umstellung zeigt Wirkung</title>
		<link>http://www.fischerlaender.net/webdev/die-kampagne-zur-php-umstellung-zeigt-wirkung</link>
		<comments>http://www.fischerlaender.net/webdev/die-kampagne-zur-php-umstellung-zeigt-wirkung#comments</comments>
		<pubDate>Wed, 10 Oct 2007 09:01:06 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/die-kampagne-zur-php-umstellung-zeigt-wirkung</guid>
		<description><![CDATA[Heute bekam ich eine E-Mail des Providers 1&#038;1, bei dem ich durch die Übernahne von Schlund und Partner mit einem Managed-Server eher ungewollt gelandet bin. Der &#8220;Platin-Service&#8221; informiert mich über die Umstellung der PHP-Version. &#8220;Cool&#8221;, so war mein erster Gedanke, &#8220;die Kampagne zur Umstellung der PHP-Version auf die aktuelle Version 5 zeigt Wirkung.&#8221; Beim genaueren [...]]]></description>
			<content:encoded><![CDATA[<p>Heute bekam ich eine E-Mail des Providers 1&#038;1, bei dem ich durch die Übernahne von Schlund und Partner mit einem Managed-Server eher ungewollt gelandet bin. Der &#8220;Platin-Service&#8221; informiert mich über die Umstellung der PHP-Version. &#8220;Cool&#8221;, so war mein erster Gedanke, &#8220;die Kampagne zur Umstellung der PHP-Version auf die aktuelle Version 5 zeigt Wirkung.&#8221;</p>
<p><img src="http://www.fischerlaender.net/wp-content/uploads/1und1-phpumstellung.png" alt="1&#038;1 PHP-Umstellungsmail" /></p>
<p>Beim genaueren Lesen der E-Mail aber überfiel mich ein milder Lachkrampf. 1&#038;1 erklärt, dass sie zum 20. November 2007 die Unterstützung von PHP3 &#8211; in Worten: PHP DREI(!) &#8211; einstellen werden und man seine Scripte doch auf PHP4 umstellen möge. Sechs Wochen bevor die Weiterentwicklung von PHP4 gestoppt wird, empfiehlt Deutschlands größter Provider seinen Kunden, auf PHP4 umzustellen. Ich verstehe ja, dass Rückwärtskompatibilität für einen Massenprovider essentiell ist, aber dann sollten sie den Kunden doch wenigstens empfehlen, gleich auf PHP5 umzustellen. Auch wenn das erst seit gut drei Jahren verfügbar ist. <img src='http://www.fischerlaender.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Das wirklich Schlimme an der Sache ist aber etwas anderes: Auf meinem 1&#038;1-Server läuft ein Projekt, das ich 2002 gestartet habe und das natürlich in PHP3 programmiert wurde. Ich habe keine Ahnung, wie das Projekt die Umstellung verkraften wird &#8211; aber wir haben auch nicht die Zeit, das bis dahin zu ändern, befürchte ich. Also lassen wir uns mal überraschen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/webdev/die-kampagne-zur-php-umstellung-zeigt-wirkung/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PHP: create_function() ist gefährlich</title>
		<link>http://www.fischerlaender.net/php/php-create_function-ist-gefaehrlich</link>
		<comments>http://www.fischerlaender.net/php/php-create_function-ist-gefaehrlich#comments</comments>
		<pubDate>Fri, 24 Aug 2007 19:19:14 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/php-create_function-ist-gefaehrlich</guid>
		<description><![CDATA[Heute durfte ich auf die harte Tour lernen, wie weit PHP manchmal noch von Perl und Python entfernt ist. So gehört in Python der Einsatz von lambda als Callback-Funktionen in Sprachkonstrukten wie filter oder reduce quasi zum guten Ton. Und hat man sich an einen derartige Programmierweise erst einmal gewöhnt, kommt einem alles andere vor [...]]]></description>
			<content:encoded><![CDATA[<p>Heute durfte ich auf die harte Tour lernen, wie weit PHP manchmal noch von Perl und Python entfernt ist. So gehört in Python der Einsatz von <code>lambda</code> als Callback-Funktionen in  Sprachkonstrukten wie <code>filter</code> oder <code>reduce</code> quasi zum guten Ton. Und hat man sich an einen derartige Programmierweise erst einmal gewöhnt, kommt einem alles andere vor wie <em>QBasic für Einsteiger</em>.</p>
<p>Natürlich hab ich auch in meinem neuesten Projekt, das zum ersten Mal auch im Backend auf PHP setzt, intensiv die PHP-Variante <a href="http://de.php.net/create_function">create_function()</a> benutzt. In etlichen <code>array_filter()</code>- oder <code>array_reduce()</code>-Konstrukten hab ich also ein create_function() eingesetzt. </p>
<p>Das faszinierende dabei: Alles funktioniert wie erwartet. Naja fast. Das Escapen von Variablen oder gar der Zugriff auf Klassenkonstanten ist ein Graus, aber irgendwie klappt&#8217;s fast immer. Bis ich ein Script schrieb und auf die 180.000 Einträge einer Tabelle losließ. Nach wenigen tausend Datensätzen ging dem Script schon der Speicher aus, wobei ich memory_limit eh schon auf 768 MB gesetzt hatte.</p>
<p>Eine detaillierte Analyse (ich hab halt Stück für Stück die einzelnen Funktionsaufrufe auskommentiert) zeigte, dass der Übeltäter eine Funktion war, in der zwei create_function()-Aufrufe steckten. Sobald ich diese durch den Aufruf zweier normaler Funktionen ersetzte, war das Memory Leak, das create_function() aufriss, gestopft. Seither benötigt das Script, selbst bei 100.000 Durchläufen, keine 5 MB.</p>
<p>Ganz offensichtlich gibt der PHP Garbage Collector den Speicher, der durch create_function() beansprucht wird, nicht zurück. Hängt wohl damit zusammen, dass PHP eine einmal erzeugte Funktion nicht überschreiben oder löschen kann. Wieder etwas mühsam gelernt; warum nur steht im PHP Manual kein Hinweis dazu? (Keine Widerrede: Die Warnungen im Diskussionsbereich zählen nicht!)</p>
<p>Jetzt habe ich also ein Script, dessen Speicherbedarf sich in Grenzen hält, der Code aber ist durch den Verzicht auf create_function() deutlich hässlicher und weniger wartbar geworden. Elegante Programmierung und PHP passen wohl immer noch nicht zusammen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/php/php-create_function-ist-gefaehrlich/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Stellenangebot: Webentwickler/in (PHP, MySQL, AJAX) gesucht</title>
		<link>http://www.fischerlaender.net/webdev/stellenangebot-webentwicklerin-php-mysql-ajax-gesucht</link>
		<comments>http://www.fischerlaender.net/webdev/stellenangebot-webentwicklerin-php-mysql-ajax-gesucht#comments</comments>
		<pubDate>Tue, 10 Jul 2007 14:57:16 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/stellenangebot-webentwicklerin-php-mysql-ajax-gesucht</guid>
		<description><![CDATA[Für meine Firma, die certo GmbH im niederbayerischen Osterhofen, suche ich für ab sofort eine(n) Webentwickler(in). Wer Spaß dran hat, in einem kleinen Team unsere bestehenden Anwendungen zu überarbeiten und neue Web 2.0-lastige Anwendungen mitzuentwickeln, findet alle weiteren Detailinformationen hier: certo-it.de/jobs. Viel Spaß an der Arbeit und eine gute Bezahlung werden garantiert.]]></description>
			<content:encoded><![CDATA[<p>Für meine Firma, die <em>certo GmbH</em> im niederbayerischen Osterhofen, suche ich für ab sofort eine(n) Webentwickler(in). Wer Spaß dran hat, in einem kleinen Team unsere bestehenden Anwendungen zu überarbeiten und neue Web 2.0-lastige Anwendungen mitzuentwickeln, findet alle weiteren Detailinformationen hier: <a href="http://www.certo-it.de/jobs/">certo-it.de/jobs</a>.<br />
Viel Spaß an der Arbeit und eine gute Bezahlung werden garantiert. <img src='http://www.fischerlaender.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/webdev/stellenangebot-webentwicklerin-php-mysql-ajax-gesucht/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to sanitize a string with mixed encodings &#8211; UTF-8 and Latin1</title>
		<link>http://www.fischerlaender.net/php/sanitize-utf8-latin1</link>
		<comments>http://www.fischerlaender.net/php/sanitize-utf8-latin1#comments</comments>
		<pubDate>Mon, 09 Jul 2007 22:03:56 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/sanitize-utf8-latin1</guid>
		<description><![CDATA[Dealing with the predominant encodings in the western world (UTF-8 and Latin1 aka ISO-8859-1) isn&#8217;t that hard &#8211; in theory. But whenever I have to deal with different encodings there&#8217;s always happening something strange. Both editors (Textmate and Smultron) I use on the Mac don&#8217;t handle files with different encodings as good as Ultraedit does [...]]]></description>
			<content:encoded><![CDATA[<p>Dealing with the predominant encodings in the western world (UTF-8 and Latin1 aka ISO-8859-1) isn&#8217;t that hard &#8211; in theory. But whenever I have to deal with different encodings there&#8217;s always happening something strange. Both editors (Textmate and Smultron) I use on the Mac don&#8217;t handle files with different encodings as good as Ultraedit does on Windows, where it&#8217;s as easy as choosing a menu entry to change the encoding of an opened file. But I digress.</p>
<p>The really painful part of dealing with encodings is when you have text files (or database entries) where the encoding is mixed. Now, in theory, there is no such thing as a &#8220;mixed encoding&#8221;: A given text is either encoded in UTF-8 or in Latin1 &#8211; or in any other encoding, but there is no such thing as &#8220;mixing&#8221;. In practice however, there can be several situations where you get text which partly is encoded in UTF-8 and partly in Latin1. Today, for example, I started to upgrade an old blog from WordPress 1.5 to the most recent version 2.2.1. During this process I looked at the various trackbacks and learned that they were sometimes encoded in UTF-8 and sometimes in Latin1.</p>
<p>To sanitize those 700+ trackbacks I wrote a little PHP class called <a href="http://www.fischerlaender.net/wp-content/uploads/Latin1UTF8">Latin1UTF8</a>. The class has two methods: <code>mixed_to_latin1($text)</code> and <code>mixed_to_utf8($text)</code>, which do what their names say. Just give them some text which may contain characters encoded in UTF-8 and/or Latin1 and you&#8217;ll get back a sanitized version.</p>
<p><code>macbook:~/Documents/source/php/utf8 sf$ /Applications/MAMP/bin/php5/bin/php Latin1UTF8.php<br />
Original: Fischerländer. FischerlÃ¤nder.<br />
Latin1:   Fischerländer. Fischerländer.<br />
UTF-8:    FischerlÃ¤nder. FischerlÃ¤nder.<br />
</code></p>
<p>Please be aware that there is no error checking! UTF-8 characters which can not be displayed in Latin1 will return garbage. While <code>Latin1UTF8</code> may give the impression that the <em>garbage in &#8211; garbage out</em> rule is no longer appropriate, be sure to give reasonable data to my little class or you&#8217;ll get some surprises.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/php/sanitize-utf8-latin1/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>phpa-norl &#8211; PHP shell for Mac OS X and Windows</title>
		<link>http://www.fischerlaender.net/php/phpa-norl</link>
		<comments>http://www.fischerlaender.net/php/phpa-norl#comments</comments>
		<pubDate>Sun, 08 Jul 2007 20:02:53 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/phpa</guid>
		<description><![CDATA[Update! Thanks for alle the nice and helpful comments. I&#8217;ve integrated the hints concerning split, register_shutdown_function and PHP_EOL. (2010/06/16) When writing code I really like to have some kind of fast feedback system, like the Smalltalk workspace or the Python IDLE shell. For Perl development I have created a graphical Perl shell for that purpose. [...]]]></description>
			<content:encoded><![CDATA[<p><b>Update!</b> <em>Thanks for alle the nice and helpful comments. I&#8217;ve integrated the hints concerning split, register_shutdown_function and PHP_EOL. (2010/06/16)</em></p>
<p>When writing code I really like to have some kind of fast feedback system, like the Smalltalk workspace or the Python IDLE shell. For Perl development I have created a <a href="http://www.fischerlaender.net/perl/perl-workspace-a-graphical-multi-line-perl-shell">graphical Perl shell</a> for that purpose.</p>
<p>Because I now have to do more and more work with PHP, I&#8217;ve been looking for a similiar tool and came across <a href="http://david.acz.org/phpa/">phpa</a>, &#8220;an interactive command line shell for PHP&#8221; from David Phillips. Unfortunately phpa needs readline which isn&#8217;t available on Mac OS X and Windows. (No, of course readline is available, but you have to compile PHP yourself to use it.)</p>
<p>So, I re-worked David&#8217;s PHP shell and removed all the fancy readline stuff. Without readline support the shell isn&#8217;t as useful as it could be, but at least it now runs on Mac OS X and I think it will also run on Windows systems. This interactive php shell without readline support I call <code>phpa-norl</code> &#8211; where the <em>norl</em> part obviously stands for &#8220;no readline&#8221; support.</p>
<p><img src="http://www.fischerlaender.net/wp-content/uploads/phpa-norl.jpg" alt="screenshot: PHP shell phpa-norl" /></p>
<h3>Installation</h3>
<p>Download the PHP shell file <a href="http://www.fischerlaender.net/wp-content/uploads/phpa-norl">phpa-norl</a> and start it with <code>php phpa-norl</code>.</p>
<p>To mimic the readline support, there is a simple history function in <code>phpa-norl</code>. Entering a single &#8216;h&#8217; lists the twenty last commands you executed. Appending a number to &#8216;h&#8217;, executes the command with that number in the history list. &#8216;h0&#8242; for example always re-executes your last command. You can also enter a multi-line statement. If the last character on your input line is a &#8216;#&#8217;, than <code>phpa-norl</code> assumes that there will follow additional code on a new line. To leave the PHP shell, just enter a simple &#8216;q&#8217; and <code>phpa-norl</code> will exit.</p>
<p>In Windows, I use a phpa.bat file containing just a single line:</p>
<pre>php c:\php\phpa.php</pre>
<p>Saving this phpa.bat in a directory within your PATH, you can invoke the shell simply by:</p>
<pre>phpa</pre>
<h3>PHP shell usage</h3>
<p>Here is a typical <code>phpa-norl</code> session:</p>
<pre>macbook:~ sf$ ./phpa-norl
PHP 5.2.0 (cli) (???) [Darwin]
>>> $a=array(17,899,324,234)
>>> $b=array(288,900,1212,2323)
>>> $c=array_merge($a,$b)
>>> sort($c,SORT_NUMERIC)
true
>>> print_r($c)
Array
(
    [0] => 17
    [1] => 234
    [2] => 288
    [3] => 324
    [4] => 899
    [5] => 900
    [6] => 1212
    [7] => 2323
)
>>> $a[]=199
>>> h
History:
[5] => $a=array(17,899,324,234)
[4] => $b=array(288,900,1212,2323)
[3] => $c=array_merge($a,$b)
[2] => sort($c,SORT_NUMERIC)
[1] => print_r($c)
[0] => $a[]=199
>>> h3
>>> $c=array_merge($a,$b)
>>> h
History:
[5] => $a=array(17,899,324,234)
[4] => $b=array(288,900,1212,2323)
[3] => sort($c,SORT_NUMERIC)
[2] => print_r($c)
[1] => $a[]=199
[0] => $c=array_merge($a,$b)
>>> h3
>>> sort($c,SORT_NUMERIC)
true
>>> h
History:
[5] => $a=array(17,899,324,234)
[4] => $b=array(288,900,1212,2323)
[3] => print_r($c)
[2] => $a[]=199
[1] => $c=array_merge($a,$b)
[0] => sort($c,SORT_NUMERIC)
>>> h3
>>> print_r($c)
Array
(
    [0] => 17
    [1] => 199
    [2] => 234
    [3] => 288
    [4] => 324
    [5] => 899
    [6] => 900
    [7] => 1212
    [8] => 2323
)
>>></pre>
<p><strong>Update:</strong><br />
Since PHP 5.1 there is (at last!) a built-in interactive mode as <a href="http://blog.thinkphp.de/archives/44-More-PHP-power-on-the-command-line.html">Johannes Schlüter shows</a> in his blog, but this interactive mode needs readline support which isn&#8217;t part of the official Windows or Mac OS X builds. <code>phpa-norl</code> addresses anyone who doesn&#8217;t like to compile PHP.</p>
<p><strong>Update:</strong><br />
Licence: phpa-norl is, like the original phpa, public domain. Feel free to do with it whatever you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/php/phpa-norl/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>PHP namespace separator</title>
		<link>http://www.fischerlaender.net/perl/php-namespace-separator</link>
		<comments>http://www.fischerlaender.net/perl/php-namespace-separator#comments</comments>
		<pubDate>Fri, 06 Jul 2007 13:15:32 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.fischerlaender.net/php/php-namespace-separator</guid>
		<description><![CDATA[I don&#8217;t want to start a Perl vs. PHP flame here, especially when both languages are heading so slooowly towards their version 6. But I just learned that there will at last be a namespace support soon(?) in PHP. And guess what the separator string will be &#8230; Yes, you&#8217;re right, it&#8217;s &#8220;::&#8221;. For a [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t want to start a Perl vs. PHP flame here, especially when both languages are heading so slooowly towards their version 6. But I just learned that <a href="http://schlitt.info/applications/blog/index.php?/archives/556-I-love-namespaces.html">there will at last be a namespace support</a> soon(?) in PHP. And guess what the separator string will be &#8230; Yes, you&#8217;re right, it&#8217;s &#8220;::&#8221;. For a Perl programmer like me this is a pleasant looking choice. I hope PHP will get the long missing namespace support soon; after all I&#8217;m about to start two brand-new PHP projects at the very moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fischerlaender.net/perl/php-namespace-separator/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
