<?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>Mats Lindh &#187; PHP</title>
	<atom:link href="http://e-mats.org/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://e-mats.org</link>
	<description>Where desperate is just another word for a regular day.</description>
	<lastBuildDate>Wed, 02 May 2012 15:12:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>php-amqplib: Uncaught exception &#8216;Exception&#8217; with message &#8216;Error reading data. Recevived 0 instead of expected 1 bytes&#8217;</title>
		<link>http://e-mats.org/2012/05/php-amqplib-uncaught-exception-exception-with-message-error-reading-data-recevived-0-instead-of-expected-1-bytes/</link>
		<comments>http://e-mats.org/2012/05/php-amqplib-uncaught-exception-exception-with-message-error-reading-data-recevived-0-instead-of-expected-1-bytes/#comments</comments>
		<pubDate>Tue, 01 May 2012 15:23:24 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[pwned.no]]></category>
		<category><![CDATA[RabbitMQ]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[php-amqplib]]></category>
		<category><![CDATA[rabbitmq]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=1028</guid>
		<description><![CDATA[I&#8217;ve been playing around with RabbitMQ recently, but trying to find out what caused the above error included a trip through wireshark and an attempt to dig through the source code of php-amqplib. It seems that it&#8217;s (usually) caused by a permission problem: either the wrong username / password combination as reported by some on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with RabbitMQ recently, but trying to find out what caused the above error included a trip through wireshark and an attempt to dig through the source code of php-amqplib. It seems that it&#8217;s (usually) caused by a permission problem: either the wrong username / password combination as reported by some on the wide internet, or by my own issue: the authenticated user didn&#8217;t have access to the vhost I tried to associate my connection with.</p>
<p>You can see the active permissions for a vhost path by using rabbitmqctl:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">sudo</span> rabbitmqctl list_permissions -p <span class="sy0">/</span>vhostname</div>
</li>
</ol>
</div>
<p>.. or you if you&#8217;ve installed the web management plugin for rabbitmq: select <strong>Virtual Hosts</strong> in the menu, then select the vhost you want to see permissions for.</p>
<p>You can give a user (all out) access to the vhost by using rabbitmqctl:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">sudo</span> rabbitmqctl set_permissions -p <span class="sy0">/</span>vhostname guest <span class="st0">&quot;.*&quot;</span> <span class="st0">&quot;.*&quot;</span> <span class="st0">&quot;.*&quot;</span></div>
</li>
</ol>
</div>
<p>.. or by adding the permissions through the web management interface, where you can select the user and the permission regexes for the user/vhost combination.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2012/05/php-amqplib-uncaught-exception-exception-with-message-error-reading-data-recevived-0-instead-of-expected-1-bytes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solr Response Empty from PHP, but Works in Browser or CURL?</title>
		<link>http://e-mats.org/2011/10/solr-response-empty-from-php-but-works-in-browser-or-curl/</link>
		<comments>http://e-mats.org/2011/10/solr-response-empty-from-php-but-works-in-browser-or-curl/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 11:20:59 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[empty response]]></category>
		<category><![CDATA[jetty]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=965</guid>
		<description><![CDATA[Weird issue that I think I&#8217;ve stumbled upon earlier, but yet again reared it&#8217;s head yesterday. Certain application containers (possibly Jetty in this case) will for some reason not produce any output from Solr (or other applications I&#8217;d guess) if the request is made with HTTP/1.0 as the version identifier (&#8220;GET /&#8230;/ HTTP/1.0&#8243; as the [...]]]></description>
			<content:encoded><![CDATA[<p>Weird issue that I think I&#8217;ve stumbled upon earlier, but yet again reared it&#8217;s head yesterday. Certain application containers (possibly Jetty in this case) will for some reason not produce any output from Solr (or other applications I&#8217;d guess) if the request is made with HTTP/1.0 as the version identifier (&#8220;GET /&#8230;/ HTTP/1.0&#8243; as the first line of the request). The native HTTP support in PHP identifies itself as HTTP/1.0 as it doesn&#8217;t support request chunking, which then turns into a magical problem with requests that used to work, but doesn&#8217;t work any longer (the response is just zero bytes in size &#8211; all other headers are identical) &#8211; but still works as expected if you open them in your browser.</p>
<p>The solution is to either gamble on the server not sending any chunked responses and <a href="http://no.php.net/manual/en/function.stream-context-create.php">then setting protocol_version in the stream context</a> that you pass to the file retrieving function (<a href="http://no.php.net/manual/en/context.http.php">the list of HTTP wrapper settings</a> (.. I don&#8217;t think it&#8217;s a good idea to define protocol_version as float, but .. well.)), or use <a href="http://no.php.net/curl">cURL</a> instead. The Solr pecl extension uses cURL internally, so it&#8217;s not affected by this issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2011/10/solr-response-empty-from-php-but-works-in-browser-or-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parse a DSN string in Python</title>
		<link>http://e-mats.org/2011/01/parse-a-dsn-string-in-python/</link>
		<comments>http://e-mats.org/2011/01/parse-a-dsn-string-in-python/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 11:46:12 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[dsn]]></category>
		<category><![CDATA[pdo]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=852</guid>
		<description><![CDATA[A simple hack to get the different parts of a DSN string (which are used in PDO in PHP): def parse_dsn&#40;dsn&#41;: &#160; &#160; m = re.search&#40;&#34;([a-zA-Z0-9]+):(.*)&#34;, dsn&#41; &#160; &#160; values = &#123;&#125; &#160; &#160; &#160; &#160; if &#40;m and m.group&#40;1&#41; and m.group&#40;2&#41;&#41;: &#160; &#160; &#160; &#160; values&#91;&#39;driver&#39;&#93; = m.group&#40;1&#41; &#160; &#160; &#160; &#160; m_options = [...]]]></description>
			<content:encoded><![CDATA[<p>A simple hack to get the different parts of a DSN string (which are used in PDO in PHP):</p>
<div class="geshi no python">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">def</span> parse_dsn<span class="br0">&#40;</span>dsn<span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; m = <span class="kw3">re</span>.<span class="me1">search</span><span class="br0">&#40;</span><span class="st0">&quot;([a-zA-Z0-9]+):(.*)&quot;</span>, dsn<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; values = <span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>m <span class="kw1">and</span> m.<span class="me1">group</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span> <span class="kw1">and</span> m.<span class="me1">group</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; values<span class="br0">&#91;</span><span class="st0">&#39;driver&#39;</span><span class="br0">&#93;</span> = m.<span class="me1">group</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; m_options = <span class="kw3">re</span>.<span class="me1">findall</span><span class="br0">&#40;</span><span class="st0">&quot;([a-zA-Z0-9]+)=([a-zA-Z0-9]+)&quot;</span>, m.<span class="me1">group</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> pair <span class="kw1">in</span> m_options:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values<span class="br0">&#91;</span>pair<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#93;</span> = pair<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> values</div>
</li>
</ol>
</div>
<p>The returned dictionary contains one entry for each of the entries in the DSN.</p>
<p>Update: helge also submitted a simplified version of the above:</p>
<div class="geshi no python">
<ol>
<li class="li1">
<div class="de1">driver, rest = dsn.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&#39;:&#39;</span>, <span class="nu0">1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">values = <span class="kw2">dict</span><span class="br0">&#40;</span><span class="kw3">re</span>.<span class="me1">findall</span><span class="br0">&#40;</span><span class="st0">&#39;(<span class="es0">\w</span>+)=(<span class="es0">\w</span>+)&#39;</span>, rest<span class="br0">&#41;</span>, driver=driver<span class="br0">&#41;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2011/01/parse-a-dsn-string-in-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Solr, Tomcat and HTTP/1.1 505 HTTP Version Not Supported</title>
		<link>http://e-mats.org/2010/05/solr-tomcat-and-http1-1-505-http-version-not-supported/</link>
		<comments>http://e-mats.org/2010/05/solr-tomcat-and-http1-1-505-http-version-not-supported/#comments</comments>
		<pubDate>Wed, 19 May 2010 10:48:50 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[version not supported]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=784</guid>
		<description><![CDATA[During today&#8217;s hacking aboot I came across the above error from our Solr query library. The error indicates that some part of Tomcat was unable to parse the &#8220;GET / HTTP/1.1&#8243; string &#8211; where it is unable to determine the &#8220;HTTP/1.1&#8243; part. A problem like this could be introduced by having a space in the [...]]]></description>
			<content:encoded><![CDATA[<p>During today&#8217;s hacking aboot I came across the above error from our Solr query library. The error indicates that some part of Tomcat was unable to parse the &#8220;GET / HTTP/1.1&#8243; string &#8211; where it is unable to determine the &#8220;HTTP/1.1&#8243; part. A problem like this could be introduced by having a space in the query string (and it not being escaped properly), so that the request would have been for &#8220;GET /?a=b c HTTP/1.1&#8243;. After running through both the working and non-working query through ngrep and wireshark, this did however not seem to be the problem. My spaces were properly escaped using plus signs (GET /?a=b+c HTTP/1.1). </p>
<p>There does however seem to be a problem (at least with our version of Tomcat &#8211; 6.0.20) which results in the +-s being resolved before the request is handed off to the code that attempts to parse the header, so even though it is properly escaped using &#8220;+&#8221;, it still barfs.</p>
<p>The solution:</p>
<p>Use %20 to escape spaces instead of + signs; simply adding str_replace(&#8221; &#8220;, &#8220;%20&#8243;, ..); in our query layer solved the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/05/solr-tomcat-and-http1-1-505-http-version-not-supported/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple PHP Hack to Print an Integer in Binary Form</title>
		<link>http://e-mats.org/2010/04/simple-php-hack-to-print-an-integer-in-binary-form/</link>
		<comments>http://e-mats.org/2010/04/simple-php-hack-to-print-an-integer-in-binary-form/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 21:29:56 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[bits]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[pastebin]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=778</guid>
		<description><![CDATA[Today: Using my own blog as a simple pastebin to remember a helper function I wrote while debugging a good selection of binary operations on integers in PHP. This will simply output the provided value as bit values (0 / 1). Wrap it in &#60;pre&#62;-s if you&#8217;re running it in a web context. $len allows [...]]]></description>
			<content:encoded><![CDATA[<p>Today: Using my own blog as a simple pastebin to remember a helper function I wrote while debugging a good selection of binary operations on integers in PHP. This will simply output the provided value as bit values (0 / 1). Wrap it in &lt;pre&gt;-s if you&#8217;re running it in a web context.</p>
<p>$len allows you do change how many bits it will print (starting from lsb &#8211; least significant bit), $blockSize adjust the amount of bits before throwing in a space.</p>
<p><code></p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> printBinary<span class="br0">&#40;</span><span class="re1">$val</span><span class="sy0">,</span> <span class="re1">$len</span> <span class="sy0">=</span> <span class="nu0">32</span><span class="sy0">,</span> <span class="re1">$blockSize</span> <span class="sy0">=</span> <span class="nu0">8</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re1">$i</span> <span class="sy0">=</span> <span class="re1">$len</span> <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span> <span class="re1">$i</span> <span class="sy0">&gt;=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="re1">$i</span><span class="sy0">--</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">print</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re1">$val</span> <span class="sy0">&amp;</span> 0x1<span class="sy0">&lt;&lt;</span><span class="re1">$i</span><span class="br0">&#41;</span> ? <span class="nu0">1</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$i</span><span class="sy0">%</span><span class="re1">$blockSize</span> <span class="sy0">==</span> <span class="nu0">0</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">print</span> <span class="br0">&#40;</span><span class="st0">&quot; &quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">print</span> <span class="br0">&#40;</span><span class="st0">&quot;<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/04/simple-php-hack-to-print-an-integer-in-binary-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing Issue With PHPs SoapClient Overwriting Duplicate Attribute and Tag Names</title>
		<link>http://e-mats.org/2010/02/fixing-issue-with-phps-soapclient-overwriting-duplicate-attribute-and-tag-names/</link>
		<comments>http://e-mats.org/2010/02/fixing-issue-with-phps-soapclient-overwriting-duplicate-attribute-and-tag-names/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 13:48:59 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[soapclient]]></category>
		<category><![CDATA[subclassing]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=750</guid>
		<description><![CDATA[The setting: An SOAP request contains an Id attribute &#8211; and an element with the exact name in the response (directly beneath the element containing the attribute &#8211; an immediate child): &#60;res z:Id=&#34;i123&#34;&#62; &#160; &#60;Id&#62;foobar&#60;/Id&#62; &#60;/res&#62; The problem is that the generated result object from the SoapClient (at least of PHP 5.2.12) contains the attribute [...]]]></description>
			<content:encoded><![CDATA[<p>The setting:</p>
<p>An SOAP request contains an Id attribute &#8211; and an element with the exact name in the response (directly beneath the element containing the attribute &#8211; an immediate child):</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;res</span> <span class="re0">z:Id</span>=<span class="st0">&quot;i123&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Id<span class="re2">&gt;</span></span></span>foobar<span class="sc3"><span class="re1">&lt;/Id<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/res<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>The problem is that the generated result object from the SoapClient (at least of PHP 5.2.12) contains the attribute value, and not the element value. In our case we could ignore the z:Id attribute, as it was simply an Id to identify the element in the response (this might be something that ASP.NET or some other .NET component does).</p>
<p>Our solution is to subclass the internal SoapClient and handle the <em>__doRequest</em> method, stripping out the part of the request that gives the wrong value for the Id field:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> Provider_SoapClient <span class="kw2">extends</span> SoapClient</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __doRequest<span class="br0">&#40;</span><span class="re1">$request</span><span class="sy0">,</span> <span class="re1">$location</span><span class="sy0">,</span> <span class="re1">$action</span><span class="sy0">,</span> <span class="re1">$version</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> parent<span class="sy0">::</span>__doRequest<span class="br0">&#40;</span><span class="re1">$request</span><span class="sy0">,</span> <span class="re1">$location</span><span class="sy0">,</span> <span class="re1">$action</span><span class="sy0">,</span> <span class="re1">$version</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st0">&#39;/ z:Id=&quot;i[0-9]+&quot;/&#39;</span><span class="sy0">,</span> <span class="st0">&#39;&#39;</span><span class="sy0">,</span> <span class="re1">$result</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re1">$result</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This removes the attribute from all the values (there is no danger that the string will be present in any other of the elements. If there is &#8211; be sure to adjust the regular expression). And voilá, it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/02/fixing-issue-with-phps-soapclient-overwriting-duplicate-attribute-and-tag-names/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Avoid Escaping Spaces in the Query String in a Solr Query</title>
		<link>http://e-mats.org/2010/01/avoid-escaping-spaces-in-the-query-string-in-a-solr-query/</link>
		<comments>http://e-mats.org/2010/01/avoid-escaping-spaces-in-the-query-string-in-a-solr-query/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 22:24:14 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[escaping]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[spaces]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=744</guid>
		<description><![CDATA[Following up on the previous post about escaping values in a Solr query string, it&#8217;s important to note that you should not escape spaces in the query itself. The reason for this is that if you escape spaces in the query &#8220;foo bar&#8221;, the search will be performed on the term &#8220;foo bar&#8221; itself, and [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on <a href="http://e-mats.org/2010/01/escaping-characters-in-a-solr-query-solr-url/">the previous post about escaping values in a Solr query string</a>, it&#8217;s important to note that you should not escape spaces in the query itself. The reason for this is that if you escape spaces in the query &#8220;foo bar&#8221;, the search will be performed on the term &#8220;foo bar&#8221; itself, and not with &#8220;foo&#8221; as one term and &#8220;bar&#8221; as the other. This will only return documents that has the string &#8220;foo bar&#8221; in sequence.</p>
<p>The solution is to either remove the space from the escape list in the previous function &#8211; and use another function for escaping values where you actually should escape the spaces &#8211; or break up the string into &#8220;escapable&#8221; parts.</p>
<p>The code included beneath performs the last task; it splits the string into different parts delimited by space and then escapes each part of the query by itself.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$queryParts</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&#39; &#39;</span><span class="sy0">,</span> <span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">getQuery</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$queryEscaped</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$queryParts</span> <span class="kw1">as</span> <span class="re1">$queryPart</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$queryEscaped</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> self<span class="sy0">::</span><span class="me2">escapeSolrValue</span><span class="br0">&#40;</span><span class="re1">$queryPart</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$queryEscaped</span> <span class="sy0">=</span> <span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&#39; &#39;</span><span class="sy0">,</span> <span class="re1">$queryEscaped</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/avoid-escaping-spaces-in-the-query-string-in-a-solr-query/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Simple Smarty Modifier to Generate a Chart Through Google Chart API</title>
		<link>http://e-mats.org/2010/01/a-simple-smarty-modifier-to-generate-a-chart-through-google-chart-api/</link>
		<comments>http://e-mats.org/2010/01/a-simple-smarty-modifier-to-generate-a-chart-through-google-chart-api/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 22:48:55 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[google chart]]></category>
		<category><![CDATA[google chart api]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=739</guid>
		<description><![CDATA[After the longest title of my blog so far follows one of the shortest posts. The function has two required parameters &#8211; the first one is provided automagically for you by smarty (it&#8217;s the value of the variable you&#8217;re applying the modifier to). This should be an array of objects containing the value you want [...]]]></description>
			<content:encoded><![CDATA[<p>After the longest title of my blog so far follows one of the shortest posts.</p>
<p>The function has two required parameters &#8211; the first one is provided automagically for you by smarty (it&#8217;s the value of the variable you&#8217;re applying the modifier to). This should be an array of objects containing the value you want to graph. The only required argument you have to provide to the modifier is the method to use for fetching the values for graphing. </p>
<p>Usage:<br />
{$objects|googlechart:&#8221;getValue&#8221;}</p>
<p>This will dynamically load your plugin from the file modifier.googlechart.php in your Smarty plugins directory, or you can register the plugin manually by calling register_modifier on the template object after you&#8217;ve created it.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> smarty_modifier_googlechart<span class="br0">&#40;</span><span class="re1">$points</span><span class="sy0">,</span> <span class="re1">$method</span><span class="sy0">,</span> <span class="re1">$size</span> <span class="sy0">=</span> <span class="st0">&quot;600&#215;200&quot;</span><span class="sy0">,</span> <span class="re1">$low</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="re1">$high</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$pointStr</span> <span class="sy0">=</span> <span class="st0">&#39;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$maxValue</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$minValue</span> <span class="sy0">=</span> INT_MAX<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$points</span> <span class="kw1">as</span> <span class="re1">$point</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&gt;</span> <span class="re1">$maxValue</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$maxValue</span> <span class="sy0">=</span> <span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&lt;</span> <span class="re1">$minValue</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$minValue</span> <span class="sy0">=</span> <span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re1">$high</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$maxValue</span> <span class="sy0">=</span> <span class="re1">$high</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$scale</span> <span class="sy0">=</span> <span class="nu0">100</span> <span class="sy0">/</span> <span class="re1">$maxValue</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$points</span> <span class="kw1">as</span> <span class="re1">$point</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$pointStr</span> <span class="sy0">.=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="re1">$point</span><span class="sy0">-&gt;</span><span class="re1">$method</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="re1">$scale</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st0">&#39;,&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$pointStr</span> <span class="sy0">=</span> <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re1">$pointStr</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">-1</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// labels (5)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$labels</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$steps</span> <span class="sy0">=</span> <span class="nu0">4</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$interval</span> <span class="sy0">=</span> <span class="re1">$maxValue</span> <span class="sy0">/</span> <span class="re1">$steps</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re1">$i</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="re1">$i</span> <span class="sy0">&lt;</span> <span class="re1">$steps</span><span class="sy0">;</span> <span class="re1">$i</span><span class="sy0">++</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$labels</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="re1">$i</span> <span class="sy0">*</span> <span class="re1">$interval</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$labels</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="re1">$maxValue</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&#39;http://chart.apis.google.com/chart?cht=lc&amp;amp;chd=t:&#39;</span> <span class="sy0">.</span> <span class="re1">$pointStr</span> <span class="sy0">.</span> <span class="st0">&#39;&amp;amp;chs=&#39;</span> <span class="sy0">.</span> <span class="re1">$size</span> <span class="sy0">.</span> <span class="st0">&#39;&amp;amp;chxt=y&amp;amp;chxl=0:|&#39;</span> <span class="sy0">.</span> <span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&#39;|&#39;</span><span class="sy0">,</span> <span class="re1">$labels</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The function does not support the short version of the Google Chart API Just Yet &#8482; as it is an simple proof of concept hack made a few months ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/a-simple-smarty-modifier-to-generate-a-chart-through-google-chart-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Dismantle An Atomic HTTP Query .. String.</title>
		<link>http://e-mats.org/2010/01/how-to-dismantle-an-atomic-http-query-string/</link>
		<comments>http://e-mats.org/2010/01/how-to-dismantle-an-atomic-http-query-string/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 20:48:40 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[dots]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[http_dismantle_query]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[underscores]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=737</guid>
		<description><![CDATA[Following up on yesterday&#8217;s gripe about PHPs (old and now useless) automagic translation of dots in GET and POST parameters to underscores, today&#8217;s edition manipulates the query string in place instead of returning it as an array. This is useful if you have a query string you want to pass on to another service, and [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on <a href="/2010/01/getting-dots-to-work-in-php-and-get-post-cookie-variable-names/">yesterday&#8217;s gripe about PHPs (old and now useless) automagic translation of dots in GET and POST parameters to underscores</a>, today&#8217;s edition manipulates the query string in place instead of returning it as an array.</p>
<p>This is useful if you have a query string you want to pass on to another service, and for some reason the default behaviour in PHP will barf barf and barf. That might happen because of the dot translation issue or that some services (such as Solr) rely on a parameter name being repeatable (in PHP the second parameter value will overwrite the first).</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> http_dismantle_query<span class="br0">&#40;</span><span class="re1">$queryString</span><span class="sy0">,</span> <span class="re1">$remove</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$removeKeys</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">is_array</span><span class="br0">&#40;</span><span class="re1">$remove</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$remove</span> <span class="kw1">as</span> <span class="re1">$removeKey</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$removeKeys</span><span class="br0">&#91;</span><span class="re1">$removeKey</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$removeKeys</span><span class="br0">&#91;</span><span class="re1">$remove</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$resultEntries</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$segments</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&quot;&amp;&quot;</span><span class="sy0">,</span> <span class="re1">$queryString</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$segments</span> <span class="kw1">as</span> <span class="re1">$segment</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$parts</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&#39;=&#39;</span><span class="sy0">,</span> <span class="re1">$segment</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$key</span> <span class="sy0">=</span> <span class="kw3">urldecode</span><span class="br0">&#40;</span><span class="kw3">array_shift</span><span class="br0">&#40;</span><span class="re1">$parts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re1">$removeKeys</span><span class="br0">&#91;</span><span class="re1">$key</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$resultEntries</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re1">$segment</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&#39;&amp;&#39;</span><span class="sy0">,</span> <span class="re1">$resultEntries</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I&#8217;m not really sure what I&#8217;ll call the next function in this series, but there sure are loads of candidates out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/how-to-dismantle-an-atomic-http-query-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Dots to Work in PHP and GET / POST / COOKIE Variable Names</title>
		<link>http://e-mats.org/2010/01/getting-dots-to-work-in-php-and-get-post-cookie-variable-names/</link>
		<comments>http://e-mats.org/2010/01/getting-dots-to-work-in-php-and-get-post-cookie-variable-names/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 22:22:21 +0000</pubDate>
		<dc:creator>Mats</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[dots]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[request variables]]></category>
		<category><![CDATA[underscore]]></category>

		<guid isPermaLink="false">http://e-mats.org/?p=735</guid>
		<description><![CDATA[One of the oldest and ugliest relics of the register_globals era of PHP are the fact that all dots in request variable names gets replaced with &#8220;_&#8221;. If your variable was named &#8220;foo.bar&#8221;, PHP will serve it to you as &#8220;foo_bar&#8221;. You cannot turn this off, you cannot use extract() or parse_str() to avoid it [...]]]></description>
			<content:encoded><![CDATA[<p>One of the oldest and ugliest relics of the register_globals era of PHP are the fact that all dots in <a href="http://no.php.net/manual/en/language.variables.external.php">request variable names gets replaced with &#8220;_&#8221;</a>. If your variable was named &#8220;foo.bar&#8221;, PHP will serve it to you as &#8220;foo_bar&#8221;. You cannot turn this off, you cannot use extract() or parse_str() to avoid it and you&#8217;re mostly left out in the dark. Luckily the QUERY_STRING enviornment (in _SERVER if you&#8217;re running mod_php, etc) contains the raw string, and this string contains the dots.</p>
<p>The following &#8220;&#8221;parser&#8221;" is a work in progress and does currently not support the array syntax for keys that PHP allow, but it solves the issue for regular vars. I will try to extend this later on to do actually replicate the functionality of the regular parser.</p>
<p>Here&#8217;s the code. No warranties. Ugly hack. You&#8217;re warned. Leave a comment if you have any good suggestions regarding this (.. or know of an existing library doing the same..).</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> http_demolish_query<span class="br0">&#40;</span><span class="re1">$queryString</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$segments</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&quot;&amp;&quot;</span><span class="sy0">,</span> <span class="re1">$queryString</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$segments</span> <span class="kw1">as</span> <span class="re1">$segment</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$parts</span> <span class="sy0">=</span> <span class="kw3">explode</span><span class="br0">&#40;</span><span class="st0">&#39;=&#39;</span><span class="sy0">,</span> <span class="re1">$segment</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$key</span> <span class="sy0">=</span> <span class="kw3">urldecode</span><span class="br0">&#40;</span><span class="kw3">array_shift</span><span class="br0">&#40;</span><span class="re1">$parts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$value</span> <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$parts</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$value</span> <span class="sy0">=</span> <span class="kw3">urldecode</span><span class="br0">&#40;</span><span class="kw3">join</span><span class="br0">&#40;</span><span class="st0">&#39;=&#39;</span><span class="sy0">,</span> <span class="re1">$parts</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span><span class="br0">&#91;</span><span class="re1">$key</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re1">$value</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="re1">$result</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>(OK, that&#8217;s not the real function name, but it&#8217;s aptly named to be the nemesis of <a href="http://no.php.net/http_build_query">http_build_query</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://e-mats.org/2010/01/getting-dots-to-work-in-php-and-get-post-cookie-variable-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

