<?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>Alexey Zakhlestins blog &#187; programming</title>
	<atom:link href="http://blog.milkfarmsoft.com/category/computers/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.milkfarmsoft.com</link>
	<description>Programming for Mac and Web</description>
	<lastBuildDate>Sun, 13 Jun 2010 15:42:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
	<atom:link rel="hub" href="http://superfeedr.com/hubbub" />
			<item>
		<title>Pake 1.4.0 is released</title>
		<link>http://blog.milkfarmsoft.com/2010/03/pake-1-4-0-is-released/</link>
		<comments>http://blog.milkfarmsoft.com/2010/03/pake-1-4-0-is-released/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 08:16:18 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[pake]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=156</guid>
		<description><![CDATA[<p>I just released new version of Pake.</p>
<p></p>
<p>Pake is a command line utility for executing predefined tasks, inspired by make. It is written in PHP and the tasks are also described in PHP. Pake can be used for compiling projects from different pieces, generating code, preprocessing templates and deploying projects.</p>
<p>If you know Phing, then Pake is a <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2010/03/pake-1-4-0-is-released/">Pake 1.4.0 is released</a></span>]]></description>
			<content:encoded><![CDATA[<p>I just released new version of <a href="http://wiki.github.com/indeyets/pake/">Pake</a>.</p>
<p></p>
<p>Pake is a command line utility for executing predefined tasks, inspired by make. It is written in PHP and the tasks are also described in PHP. Pake can be used for compiling projects from different pieces, generating code, preprocessing templates and deploying projects.</p>
<p>If you know Phing, then Pake is a similar thing, but doesn&#8217;t use XML, is easier to use and faster.</p>
<p></p>
<p>Here&#8217;s the brief Changelog:</p>
<ul>
<li>added &#8220;interactive mode&#8221; (pake -i)</li>
<li>new helper: pakeMercurial (in addition to pakeSubversion and pakeGit we already had)</li>
<li>updated sfYaml library</li>
<li>use copy+unlink instead of rename in pake_rename() to workaround problem of moving files between volumes</li>
<li>&#8220;pake compact&#8221; (developers-only) command works again</li>
<li>added explicit pakePearTask::package_pear_package($file, $target) method</li>
<li>fixed output-formatting (long texts in exceptions, etc.)</li>
<li>various packaging fixes</li>
</ul>
<p>All Pake 1.x versions are compatible with php-5.2. Earlier versions might work, but those are not tested.</p>
<p>If you need automation tool for your project, then Pake might be exactly what you need.</p>
<p></p>
<p>Useful links:</p>
<ul>
<li><a href="http://wiki.github.com/indeyets/pake/" title="Pake">Pake&#8217;s homepage</a> (including documentation)</li>
<li><a href="http://wiki.github.com/indeyets/pake/installing-pake" title="Installing Pake">Installation instructions</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2010/03/pake-1-4-0-is-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ode to mb_ereg functions</title>
		<link>http://blog.milkfarmsoft.com/2009/11/ode-to-mb_ereg-functions/</link>
		<comments>http://blog.milkfarmsoft.com/2009/11/ode-to-mb_ereg-functions/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 00:28:20 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=151</guid>
		<description><![CDATA[There is a common misunderstanding, that mb_ereg_* functions are just unicode counterparts of ereg_* functions: slow and non-powerful. That's as far from truth as it can be. <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2009/11/ode-to-mb_ereg-functions/">ode to mb_ereg functions</a></span>]]></description>
			<content:encoded><![CDATA[<p>PHP has some sets of functions, which are not known to the wide audience. One of those is mb_ereg_* family of functions.</p>
<p>There is a common misunderstanding, that mb_ereg_* functions are just unicode counterparts of ereg_* functions: slow and non-powerful. That&#8217;s as far from truth as it can be.</p>
<p>mb_ereg_* functions are based on <a href="http://www.geocities.jp/kosako3/oniguruma/" title="Oniguruma">oniguruma</a> regular expressions library. And oniguruma is one of the fastest and most capable regular expression libraries out there. Couple of years ago I made <a href="http://blog.milkfarmsoft.com/2006/12/regexps-in-php-again/" title="Alexey Zakhlestins blog  &raquo; regexps in PHP, again">a little speed-test</a>.</p>
<p>Anyway, this time, I was going to tell about it&#8217;s usage. PHP-documentation isn&#8217;t telling much.</p>
<p>Let&#8217;s start with the basic fact: you don&#8217;t need to put additional delimeters around your regular exprsssions, when you use mb_ereg_* funcitons. For example:</p>
<pre>// find first substring consisting of letters from 'a' to 'c' in 'abcdabc' string.
<a href="http://docs.php.net/mb_ereg" title="PHP: mb_ereg - Manual">mb_ereg</a>('[a-c]+', 'abcdabc', $res);</pre>
<p>To execute same search, but in case-insensitive fashion, you should use <a href="http://docs.php.net/mb_eregi" title="PHP: mb_eregi - Manual">mb_eregi</a>()</p>
<p>mb_ereg(), mb_eregi() and mb_split() functions use pre-set options in their work. You can check current options and set the new ones using <a href="http://docs.php.net/mb_regex_set_options" title="PHP: mb_regex_set_options - Manual">mb_regex_set_options</a>() function. This function is parametrized by string, each letter of which means something.</p>
<p>There are parameters (you can specify several of these at the same time):</p>
<ul>
<li>&#8216;i&#8217;: ONIG_OPTION_IGNORECASE;</li>
<li>&#8216;x&#8217;: ONIG_OPTION_EXTEND;</li>
<li>&#8216;m&#8217;: ONIG_OPTION_MULTILINE;</li>
<li>&#8216;s&#8217;: ONIG_OPTION_SINGLELINE;</li>
<li>&#8216;p&#8217;: ONIG_OPTION_MULTILINE | ONIG_OPTION_SINGLELINE;</li>
<li>&#8216;l&#8217;: ONIG_OPTION_FIND_LONGEST;</li>
<li>&#8216;n&#8217;: ONIG_OPTION_FIND_NOT_EMPTY;</li>
<li>&#8216;e&#8217;: eval() resulting code</li>
</ul>
<p>And there are &#8220;modes&#8221; (if you specify several of these, the LAST one will be used):</p>
<ul>
<li>&#8216;j&#8217;: ONIG_SYNTAX_JAVA;</li>
<li>&#8216;u&#8217;: ONIG_SYNTAX_GNU_REGEX;</li>
<li>&#8216;g&#8217;: ONIG_SYNTAX_GREP;</li>
<li>&#8216;c&#8217;: ONIG_SYNTAX_EMACS;</li>
<li>&#8216;r&#8217;: ONIG_SYNTAX_RUBY;</li>
<li>&#8216;z&#8217;: ONIG_SYNTAX_PERL;</li>
<li>&#8216;b&#8217;: ONIG_SYNTAX_POSIX_BASIC;</li>
<li>&#8216;d&#8217;: ONIG_SYNTAX_POSIX_EXTENDED;</li>
</ul>
<p>Descriptions of these constants are available in this document: <a href="http://www.geocities.jp/kosako3/oniguruma/doc/API.txt">API.txt</a></p>
<p>So, for example, mb_regex_set_options(&#8216;pr&#8217;) is equivalent to mb_regex_set_options(&#8216;msr&#8217;) and means:</p>
<ul>
<li>. should include \n (aka &#8220;multiline-match&#8221;)</li>
<li>^ is equivalent to \A, $ is equivalent to \Z (aka &#8220;strings are single-lined&#8221;)</li>
<li>using RUBY-mode</li>
</ul>
<p>By the way, that is the default setting for mb_ereg_* functions. And, mb_ereg_match and mb_ereg_search families of functions take options-parameter explicitly.</p>
<p>So, back to functions:</p>
<pre>// make sure, that the whole string matches the regexp:
<a href="http://docs.php.net/mb_ereg_match" title="PHP: mb_ereg_match - Manual">mb_ereg_match</a>('[a-c]+', $user_string, 'pz'); // 'pz' specifies options for this operation
                                             // (multiline perl-mode in this case)

// replace any of letters from 'a' to 'c' range with 'Z'
$output = <a href="http://docs.php.net/mb_ereg_replace" title="PHP: mb_ereg_replace - Manual">mb_ereg_replace</a>('[a-c]', 'Z', $user_string, 'b'); // use basic POSIX mode</pre>
<p>Ok, these were easy and similar to what you&#8217;ve seen in preg_* functions. Now, to something more powerful. The real strength lies in mb_ereg_search_* functions. The idea is, that you can let oniguruma preparse and cache text and/or regexp in its internal buffers. If you do, matching will work a lot faster.</p>
<pre><a href="http://docs.php.net/mb_ereg_search_init" title="PHP: mb_ereg_search_init - Manual">mb_ereg_search_init</a>($some_long_text); // preparse text
<a href="http://docs.php.net/mb_ereg_search" title="PHP: mb_ereg_search - Manual">mb_ereg_search</a>('[a-c]'); // execute search
while ($r = <a href="http://docs.php.net/mb_ereg_search_getregs" title="PHP: mb_ereg_search_getregs - Manual">mb_ereg_search_getregs</a>()) { // get next result
    // work with matched result
}

mb_ereg_search('[d-e]'); // execute different search on the same text

mb_ereg_search_init($some_other_text); // preparse another text
mb_ereg_search(); // execute search using previous (already preparsed) regexp</pre>
<p>This is the fastest way of parsing large documents in php, as far as I know.</p>
<p>Notes on charsets. Though, it is often mentioned, that mb_ereg_* functions are &#8220;unicode&#8221;, it would be more practical to say, that they are encoding-aware. It is a good idea to specify, which encoding you use beore calling oniguruma.</p>
<p>Some options:</p>
<pre><a href="http://docs.php.net/mb_regex_encoding" title="PHP: mb_regex_encoding - Manual">mb_regex_encoding</a>('UTF-8');
mb_regex_encoding('CP1251'); // windows cyrillic encoding
mb_regex_encoding('Shift_JIS'); // japanese</pre>
<p>Check the <a href="http://docs.php.net/manual/en/mbstring.encodings.php" title="PHP: Summaries of supported encodings - Manual">full list of supported encodings</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2009/11/ode-to-mb_ereg-functions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>XSLCache in PECL</title>
		<link>http://blog.milkfarmsoft.com/2009/08/xslcache-in-pecl/</link>
		<comments>http://blog.milkfarmsoft.com/2009/08/xslcache-in-pecl/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 15:50:42 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=136</guid>
		<description><![CDATA[<p>XSLCache extension for PHP, originally developed by NYTimes started its second life in PECL&#8217;s repository and I am proud to announce first PECL-release.</p>
<p>The XSL Cache extension is a modification of PHP&#8217;s standard XSL extension that caches the parsed XSL stylesheet representation between sessions for 2.5x boost in performance for sites that repeatedly apply the same transform. <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2009/08/xslcache-in-pecl/">XSLCache in PECL</a></span>]]></description>
			<content:encoded><![CDATA[<p>XSLCache extension for PHP, originally developed by NYTimes started its second life in PECL&#8217;s repository and I am proud to announce <a href="http://pecl.php.net/package/xslcache">first PECL-release</a>.</p>
<p>The XSL Cache extension is a modification of PHP&#8217;s standard XSL extension that caches the parsed XSL stylesheet representation between sessions for 2.5x boost in performance for sites that repeatedly apply the same transform. API-wise it is compatible with usual <a href="http://docs.php.net/manual/en/book.xsl.php">XSL extension</a> with two small exceptions:</p>
<ol>
<li>instead of XSLTProcessor class you should use <strong>XSLTCache</strong> class.</li>
<li>importStyleshet method has another &#8220;signature&#8221;: <strong>void importStylesheet(string $path, bool $cachesheet=true);</strong></li>
</ol>
<p>Installation, from now on, should be as simple as &#8220;<strong>pecl install xslcache</strong>&#8220;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2009/08/xslcache-in-pecl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Pake: PHP project build system</title>
		<link>http://blog.milkfarmsoft.com/2009/08/pake-php5-project-build-system/</link>
		<comments>http://blog.milkfarmsoft.com/2009/08/pake-php5-project-build-system/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 14:03:33 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=127</guid>
		<description><![CDATA[Pake project wasn't maintained for a while, so I decided to give it a spin (as there is a good chance, that I will be able to use it for my current projects). I imported it's version history to GitHub. My plan is to add some generally usable helpers to current branch, write some documentation and then to start work on Pake2 which would use all new features of PHP-5.3 (namespaces, closures, rich SPL). <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2009/08/pake-php5-project-build-system/">Pake: PHP project build system</a></span>]]></description>
			<content:encoded><![CDATA[<p>Sometimes, there are pieces of software, which are unfairly forgotten. Let&#8217;s talk about one these.</p>
<p>Often, while working on software projects, one finds, that there are repetitive tasks, which would be much easier to deal with, if automated. In the C/Unix world, this task is often solved by <a href="http://en.wikipedia.org/wiki/Make_(software)">Make</a>, Java programmers prefer <a href="http://en.wikipedia.org/wiki/Ant_(software)">Apache Ant</a>, Ruby programmers use <a href="http://en.wikipedia.org/wiki/Rake_(software)">Rake</a>. The fact, which is not commonly known, is, that PHP also has such instrument, and it is called <strong>Pake</strong>. It was originally created by authors of <a href="http://www.symfony-project.org/">Symfony framework</a>. Unfortunately, they never wrote any documentation, which killed adoption rates.</p>
<p>To start automating something, you need to create Pakefile.php in the root-directory of your project, define some tasks inside and run them with &#8220;pake taskname&#8221; from command-line. The good news is, that tasks are defined in PHP language and syntax is quite simple:</p>
<div class="php" style="font-family: monospace; color: #000000;"><span style="color: #000000; font-weight: bold;">&lt;?php</span></p>
<p>pake_desc<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;FOO task&#8217;</span><span style="color: #66cc66;">&#41;</span>;<br />pake_task<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;foo&#8217;</span>, <span style="color: #ff0000;">&#8216;bar&#8217;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>pake_desc<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;BAR task&#8217;</span><span style="color: #66cc66;">&#41;</span>;<br />pake_task<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;bar&#8217;</span>, <span style="color: #ff0000;">&#8216;baz&#8217;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>pake_desc<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;BAZ task&#8217;</span><span style="color: #66cc66;">&#41;</span>;<br />pake_task<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;baz&#8217;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>pake_alias<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;default&#8217;</span>, <span style="color: #ff0000;">&#8216;foo&#8217;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// marking foo as default task</span></p>
<p><span style="color: #000000; font-weight: bold;">function</span> run_foo<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$task</span>, <span style="color: #0000ff;">$args</span><span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; <a style="text-decoration: none;" href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;foo<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;<br /><span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #000000; font-weight: bold;">function</span> run_bar<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$task</span>, <span style="color: #0000ff;">$args</span><span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; <a style="text-decoration: none;" href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;bar<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;<br /><span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #000000; font-weight: bold;">function</span> run_baz<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$task</span>, <span style="color: #0000ff;">$args</span><span style="color: #66cc66;">&#41;</span><br /><span style="color: #66cc66;">&#123;</span><br />&nbsp; &nbsp; <a style="text-decoration: none;" href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;baz<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;<br /><span style="color: #66cc66;">&#125;</span></div>
<p>I defined 3 rules, gave them descriptions and specified dependencies. Additionally, I specifed default rule. Now, we can play with this a bit. Create file with this contents, save it somewhere, and point your terminal to the same directory.</p>
<p><code><br />
> pake<br />
baz<br />
bar<br />
foo<br />
</code></p>
<p>What happened? Pake looks for &#8220;default&#8221; task in the pakefile. We defined &#8220;foo&#8221; as default. Pake found out, that foo depends on bar, and bar depends on baz. So, Pake runs &#8220;baz&#8221;, then &#8220;bar&#8221; and then, finally, &#8220;foo&#8221;. That is as simple as it can be.</p>
<p>Pake has builtin support for basic file-operations (pake_mkdirs(), pake_copy(), pake_rename(), pake_remove()), which are the powered-up versions of php&#8217;s filesystem-functions, templating (pake_replace_tokens()), directory-mirroring (pake_mirror()) and runners for creating PEAR-packages, <a href="http://phing.info/trac/">Phing</a>-commands and <a href="http://www.simpletest.org/">Simpletest</a>.</p>
<p>Pake project wasn&#8217;t maintained for a while, so I decided to give it a spin (as there is a good chance, that I will be able to use it for my current projects). I imported it&#8217;s version history to GitHub. You can find latest version here: <a href="http://github.com/indeyets/pake">http://github.com/indeyets/pake</a></p>
<p>My plan is to add some generally usable helpers to current branch, write some documentation and then to start work on Pake2 which would use all new features of PHP-5.3 (namespaces, closures, rich SPL).</p>
<p>Git-project is a source for creating pear-package. To build one use the following command:</p>
<p><code><br />
> php bin/pake.php release 1.1.0a1<br />
</code></p>
<p>it will create &#8220;pake-1.1.0a1.tgz&#8221; file in the same directory. You can install it with the following command:</p>
<p><code><br />
> pear install -f pake-1.1.0a1.tgz<br />
</code></p>
<p>If you want to grab a prebuild pear-package of pake, you can do it <a href="http://github.com/indeyets/pake/downloads">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2009/08/pake-php5-project-build-system/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>work with TwitterData in PHP</title>
		<link>http://blog.milkfarmsoft.com/2009/08/work-with-twitterdata-in-php/</link>
		<comments>http://blog.milkfarmsoft.com/2009/08/work-with-twitterdata-in-php/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 19:36:35 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=106</guid>
		<description><![CDATA[I recently created a small library for working with twitterdata in PHP. Sources are available from GitHub. Twitter Data is a simple, open, semi-structured format for embedding machine-readable, yet human-friendly, data in Twitter messages. <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2009/08/work-with-twitterdata-in-php/">work with TwitterData in PHP</a></span>]]></description>
			<content:encoded><![CDATA[<p>I recently created a small library for working with <a href="http://twitterdata.org/" target="_blank">twitterdata</a> in PHP. Sources are available from GitHub: <a href="http://github.com/indeyets/php-twitterdata/tree/master">php-twitterdata</a></p>
<p>Here&#8217;s the description from Twitter Data site:</p>
<blockquote><p>
Twitter Data is a simple, open, semi-structured format for embedding machine-readable, yet human-friendly, data in <a href="http://twitter.com/">Twitter</a> messages. This data can then be transmitted, received, and interpreted in real time by powerful new kinds of applications built on the Twitter platform. Here is an example Twitter Data message:</p>
<p><code>I love the #twitterdata proposal! $vote +1</code></p>
<p>The part with the dollar sign, $vote +1, is a piece of data embedded using the Twitter Data format.
</p></blockquote>
<p>To use php-twitterdata library, <a href="http://github.com/indeyets/php-twitterdata/downloads">download</a> it into the sub-direcory in your project&#8217;s directory (or any other place you like) and init the autoloader:</p>
<div class="php" style="font-family: monospace; color: #000000;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /><span style="color: #2500B9; font-weight: bold;">require</span> <span style="color: #ff0000;">&#8216;php-twitterdata/autoload.php&#8217;</span>;<br /><span style="color: #000000; font-weight: bold;">?&gt;</span></div>
<p>PHP API provided by php-twitterdata has 2 layers. On lower level, there are 3 classes: <a href="http://github.com/indeyets/php-twitterdata/blob/e59c94763f60deb9701a380101047d9cb6586245/TwitterData_Message.php#L12" target="_blank">TwitterData_Message</a>, <a href="http://github.com/indeyets/php-twitterdata/blob/e59c94763f60deb9701a380101047d9cb6586245/TwitterData_Frame.php#L12" target="_blank">TwitterData_Frame</a> and <a href="http://github.com/indeyets/php-twitterdata/blob/e59c94763f60deb9701a380101047d9cb6586245/TwitterData_Tuple.php#L12" target="_blank">TwitterData_Tuple</a> which correspond to parts of data-enabled twitter-message. Message can consist of several Frames, Frame can consist of several Tuples and a &#8220;subject&#8221;. Objects of each of these classes can be created programmatically and combined in hierarchy. Each of them has &#8220;magic&#8221; <a href="http://docs.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring" target="_blank">__toString()</a> method, so, to export them as a valid twitter-message, you just need to put objects in string context. Something like this:</p>
<div class="php" style="font-family: monospace; color: #000000;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /><span style="color: #0000ff;">$tuple</span> = <span style="color: #000000; font-weight: bold;">new</span> TwitterData_Tuple<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;foo&#8217;</span>, <span style="color: #ff0000;">&#8216;bar&#8217;</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #0000ff;">$frame</span> = <span style="color: #000000; font-weight: bold;">new</span> TwitterData_Frame<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Hello, world!&#8217;</span>, <a style="text-decoration: none;" href="http://docs.php.net/array" target="_blank"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$tuple</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br /><a style="text-decoration: none;" href="http://docs.php.net/echo" target="_blank"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$frame</span>;<br /><span style="color: #000000; font-weight: bold;">?&gt;</span></div>
<p>and the result will be:<br />
<code><br />
Hello, world! $foo bar<br />
</code></p>
<p>If you need to parse Twitter Data messages you should use <a href="http://github.com/indeyets/php-twitterdata/blob/e59c94763f60deb9701a380101047d9cb6586245/TwitterData_Parser.php#L29" target="_blank">TwitterData_Parser</a> class. It is a SAX-style parser, with DOM-style export. If all you need is a hierarchy of objects, use it like this:</p>
<div class="php" style="font-family: monospace; color: #000000;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /><span style="color: #0000ff;">$parser</span> = <span style="color: #000000; font-weight: bold;">new</span> TwitterData_Parser<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$text_from_twitter</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #0000ff;">$message</span> = <span style="color: #0000ff;">$parser</span>-&gt;<span style="color: #006600;">export</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// $message is object of TwitterData_Message class</span><br /><span style="color: #000000; font-weight: bold;">?&gt;</span></div>
<p>Otherwise, you can specify another handler-class as a second parameter of constructor. Such class has to implement <a href="http://github.com/indeyets/php-twitterdata/blob/e59c94763f60deb9701a380101047d9cb6586245/TwitterData_Parser.php#L12" target="_blank">TwitterData_Parser_CallbackInterface</a>.</p>
<p>Does it all sound too complex? No problem!</p>
<p>php-twitterdata library also includes high-level interface, which consists of 2 simple functions: <a href="http://github.com/indeyets/php-twitterdata/blob/e59c94763f60deb9701a380101047d9cb6586245/TwitterData.php#L14" target="_blank">TwitterData::array_to_TwitterData()</a> and <a href="http://github.com/indeyets/php-twitterdata/blob/e59c94763f60deb9701a380101047d9cb6586245/TwitterData.php#L19" target="_blank">TwitterData::TwitterData_to_array()</a>. First one converts associative array into the string, which can be inserted into twitter-message, and second one takes message-string received from twitter and returns associative array parsed out of tuples from the first frame of message (If you need to get all possible data from message, you will still need to use low-level API).</p>
<p>Example of high-level API:</p>
<div class="php" style="font-family: monospace; color: #000000;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />TwitterData::<span style="color: #006600;">TwitterData_to_array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Hello, world! $foo bar&#8217;</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #808080; font-style: italic;">// array(&#8216;foo&#8217; =&gt; &#8216;bar&#8217;);</span></p>
<p><span style="color: #0000ff;">$message</span> = <span style="color: #ff0000;">&#8216;Hello, world! &#8216;</span>.TwitterData::<span style="color: #006600;">array_to_TwitterData</span><span style="color: #66cc66;">&#40;</span><a style="text-decoration: none;" href="http://docs.php.net/array" target="_blank"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;foo&#8217;</span> =&gt; <span style="color: #ff0000;">&#8216;bar&#8217;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #808080; font-style: italic;">// Hello, world! $foo bar</span><br /><span style="color: #000000; font-weight: bold;">?&gt;</span></div>
<p>Library has <a href="http://github.com/indeyets/php-twitterdata/tree/e5f7ae14a65ed00368e23750de1addaac20f5684/tests" target="_blank">unit-tests</a>, which cover all examples provided on Twitter Data site both on <a href="http://twitterdata.org/" target="_blank">Introduction</a> page and on <a href="http://twitterdata.org/examples/" target="_blank">Examples</a> page and is licensed under <a href="http://github.com/indeyets/php-twitterdata/blob/e5f7ae14a65ed00368e23750de1addaac20f5684/LICENSE#L1" target="_blank">MIT-style license</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2009/08/work-with-twitterdata-in-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Move to GitHub</title>
		<link>http://blog.milkfarmsoft.com/2009/08/move-to-github/</link>
		<comments>http://blog.milkfarmsoft.com/2009/08/move-to-github/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 18:05:16 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql query builder]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=101</guid>
		<description><![CDATA[<p>Just notifying all interested parties, that my &#8220;Application Server in PHP&#8221; and &#8220;MySQL Query Builder&#8221; projects are moved to GitHub.</p>
<p>Their new homes are:</p>

Application Server in PHP
MySQL Query Builder

<p>p.s. newest release of MySQL Query Builder has support for subqueries in <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2009/08/move-to-github/">Move to GitHub</a></span>]]></description>
			<content:encoded><![CDATA[<p>Just notifying all interested parties, that my &#8220;<a href="http://blog.milkfarmsoft.com/?p=51">Application Server in PHP</a>&#8221; and &#8220;<a href="http://blog.milkfarmsoft.com/?p=55">MySQL Query Builder</a>&#8221; projects are moved to GitHub.</p>
<p>Their new homes are:</p>
<ul>
<li><a href="http://github.com/indeyets/appserver-in-php/tree/master">Application Server in PHP</a></li>
<li><a href="http://github.com/indeyets/MySQL-Query-Builder/tree/master">MySQL Query Builder</a></li>
</ul>
<p>p.s. newest <a href="http://github.com/indeyets/MySQL-Query-Builder/downloads">release of MySQL Query Builder </a>has support for subqueries in <strong>IN(…)</strong> statements</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2009/08/move-to-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP-FPM is BSD-licensed now</title>
		<link>http://blog.milkfarmsoft.com/2009/06/php-fpm-is-bsd-licensed-now/</link>
		<comments>http://blog.milkfarmsoft.com/2009/06/php-fpm-is-bsd-licensed-now/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 06:25:16 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=88</guid>
		<description><![CDATA[It took several years of waiting, but, it finally happened. PHP-FPM project is officially BSD-licensed now and has good chances to become a part of official PHP distribution. <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2009/06/php-fpm-is-bsd-licensed-now/">PHP-FPM is BSD-licensed now</a></span>]]></description>
			<content:encoded><![CDATA[<p>Some seriously good news here. It took several years of waiting, but, it finally happened. <a href="http://php-fpm.anight.org/" title="php-fpm: PHP FastCGI Process Manager">PHP-FPM</a> project is <a href="http://groups.google.com/group/highload-php-en/browse_thread/thread/974eaff4ad094391">officially BSD-licensed</a> now, which means, that it has good chances to become a part of official PHP distribution.</p>
<p>PHP-FPM is &#8220;deciphered&#8221; as &#8220;PHP FastCGI Process Manager&#8221; and is a patch for php to greatly improve FastCGI SAPI usage in production. It adds a bunch of additional features to php&#8217;s fastcgi such as: easy php-process daemonization (with ability to specify uid/gid/chroot/log-file), safe php-processes restart (without losing requests), custom error-handling and accelerated file-upload support (requires additional support from web-server).</p>
<p>There&#8217;s not much documentation in english, currently, but, again, there is a good chance that it will be added really soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2009/06/php-fpm-is-bsd-licensed-now/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>C, headers</title>
		<link>http://blog.milkfarmsoft.com/2008/07/c-headers/</link>
		<comments>http://blog.milkfarmsoft.com/2008/07/c-headers/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 07:52:22 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=84</guid>
		<description><![CDATA[<p>The concept of headers in C was necessary at its time, but these days it just makes compilation of complex program in complex environment several times more complex. Whenever you have several package-roots (I have /usr, /usr/local, /sw, /opt/local, /opt/some_pkg1, /opt/some_pkg2 at the same time), which have different versions of the same libraries, you need to <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2008/07/c-headers/">C, headers</a></span>]]></description>
			<content:encoded><![CDATA[<p>The concept of <a href="http://en.wikipedia.org/wiki/Header_files">headers</a> in C was necessary at its time, but these days it just makes compilation of complex program in complex environment several times more complex. Whenever you have several package-roots (I have /usr, /usr/local, /sw, /opt/local, /opt/some_pkg1, /opt/some_pkg2 at the same time), which have different versions of the same libraries, you need to separately check resolution order of libraries and header-files.</p>
<p>Sometimes it feels completely counter-intuitive and you just end up manually hiding some files.</p>
<p>Common end-user solution is just sticking to the package-root provided by distribution (usually &#8220;/usr&#8221;), but that is not an option for developer, who needs to test different combinations of bleeding-edge apps.</p>
<p>How do you manage this stuff?</p>
<p>Example. I need to build php6 (installation prefix /opt/php6) with:</p>
<ul>
<li>iconv from /sw (whle there is other iconv in /usr)</li>
<li>libxml from /usr (while there is other libxml in /sw)</li>
<li>icu from /sw/local (while there are pieces of other icu&#8217;s in /sw and /usr)</li>
</ul>
<p>In reality, there are more libs involved, and complexity arises, when these different libs are needed by the same components of php. I start thinking, that I should create some special package-root and just symlink every needed library in it. And just give it as the only package-root to php. Seems like a complex task, while considering all dependencies.</p>
<p>In my ideal world, there would be no name-resolution at all, compiler would just require exact position of library (which would be represented by the single file)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2008/07/c-headers/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WWDC and LLVM</title>
		<link>http://blog.milkfarmsoft.com/2008/06/wwdc-and-llvm/</link>
		<comments>http://blog.milkfarmsoft.com/2008/06/wwdc-and-llvm/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 08:12:20 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[llvm]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=83</guid>
		<description><![CDATA[<p>Two news:</p>

LLVM 2.3 is supposed to be released today (what&#8217;s new?)
WWDC 2008 is starting today

<p>I wonder, if that <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2008/06/wwdc-and-llvm/">WWDC and LLVM</a></span>]]></description>
			<content:encoded><![CDATA[<p>Two news:</p>
<ol>
<li><a href="http://llvm.org/">LLVM</a> 2.3 is supposed to be released today (<a href="http://llvm.org/docs/ReleaseNotes.html#whatsnew">what&#8217;s new?</a>)</li>
<li><a href="http://developer.apple.com/wwdc/">WWDC</a> 2008 is starting today</li>
</ol>
<p>I wonder, if that is coincidence</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2008/06/wwdc-and-llvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spread constants</title>
		<link>http://blog.milkfarmsoft.com/2008/05/spread-constants/</link>
		<comments>http://blog.milkfarmsoft.com/2008/05/spread-constants/#comments</comments>
		<pubDate>Wed, 07 May 2008 09:42:36 +0000</pubDate>
		<dc:creator>indeyets</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[data management]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.milkfarmsoft.com/?p=82</guid>
		<description><![CDATA[<p>Playing with Spread Toolkit. Absolutely love their constant-names  </p>

UNRELIABLE_MESS
RELIABLE_MESS
FIFO_MESS
CAUSAL_MESS
AGREED_MESS
SAFE_MESS
REGULAR_MESS

<p></p>
<p>p.s. freshly released php binding <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.milkfarmsoft.com/2008/05/spread-constants/">Spread constants</a></span>]]></description>
			<content:encoded><![CDATA[<p>Playing with <a href="http://www.spread.org/" title="The Spread Toolkit">Spread Toolkit</a>. Absolutely love their constant-names <img src='http://blog.milkfarmsoft.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<ul>
<li>UNRELIABLE_MESS</li>
<li>RELIABLE_MESS</li>
<li>FIFO_MESS</li>
<li>CAUSAL_MESS</li>
<li>AGREED_MESS</li>
<li>SAFE_MESS</li>
<li>REGULAR_MESS</li>
</ul>
<p></p>
<p>p.s. freshly released php binding is <a href="http://pecl.php.net/package/spread" title="PECL :: Package :: spread">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.milkfarmsoft.com/2008/05/spread-constants/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
