<?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>Jontas &#187; php5</title>
	<atom:link href="http://www.f15ijp.com/tag/php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.f15ijp.com</link>
	<description>My digital notepad (notes etc)</description>
	<lastBuildDate>Wed, 28 Dec 2011 18:24:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP raw POST data</title>
		<link>http://www.f15ijp.com/2011/07/22/php-raw-post-data/</link>
		<comments>http://www.f15ijp.com/2011/07/22/php-raw-post-data/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 14:31:07 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP4]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[$_POST]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[POST]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=837</guid>
		<description><![CDATA[To read the raw data being posted to a php page (for instance when $_POST is empty due to problems with encoding types or $HTTP_RAW_POST_DATA not being readable due to php.ini settings) reading file_get_contents is a nice solution. $postData = file_get_contents&#40;'php://input'&#41;;]]></description>
			<content:encoded><![CDATA[<p>To read the raw data being posted to a php page (for instance when $_POST is empty due to problems with encoding types or $HTTP_RAW_POST_DATA not being readable due to php.ini settings) reading file_get_contents is a nice solution.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$postData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php://input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2011/07/22/php-raw-post-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Send a mail as UTF-8</title>
		<link>http://www.f15ijp.com/2011/03/01/php-send-a-mail-as-utf-8/</link>
		<comments>http://www.f15ijp.com/2011/03/01/php-send-a-mail-as-utf-8/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 13:02:08 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHP5]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=778</guid>
		<description><![CDATA[To send a mail from PHP encoded as UTF-8 is fairly easy to do by modifying the headers. //Sender with special chars (UTF-8) encoded mail&#40;'mail@example.com', '=?UTF-8?B?'.base64_encode&#40;$subjectString&#41;.'?=', $messageString, &#34;MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n&#34;&#41;; //Sender not UTF-8 encoded mail&#40;'mail@example.com', 'sender@mail.com', $messageString, &#34;MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n&#34;&#41;;]]></description>
			<content:encoded><![CDATA[<p>To send a mail from PHP encoded as UTF-8 is fairly easy to do by modifying the headers.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Sender with special chars (UTF-8) encoded</span>
<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mail@example.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'=?UTF-8?B?'</span><span style="color: #339933;">.</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subjectString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?='</span><span style="color: #339933;">,</span> <span style="color: #000088;">$messageString</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Content-type: text/plain; charset=UTF-8<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Sender not UTF-8 encoded</span>
<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mail@example.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sender@mail.com'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$messageString</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Content-type: text/plain; charset=UTF-8<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2011/03/01/php-send-a-mail-as-utf-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP showing the name of the current file</title>
		<link>http://www.f15ijp.com/2010/12/16/php-showing-the-name-of-the-current-file/</link>
		<comments>http://www.f15ijp.com/2010/12/16/php-showing-the-name-of-the-current-file/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 13:55:23 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[current file]]></category>
		<category><![CDATA[include]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=756</guid>
		<description><![CDATA[Sometimes there is a need to show the name of the current file. Using $_SERVER['PHP_SELF'] will only show the file that is executed (not the a included file) Using __FILE__ gives the current file (with a full path) For this example running.php is accessed in the browser/cli. //included.php &#60;?php echo $_SERVER&#91;'PHP_SELF'&#93;; //will show running.php echo [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes there is a need to show the name of the current file.<br />
Using $_SERVER['PHP_SELF'] will only show the file that is executed (not the a included file)<br />
Using __FILE__ gives the current file (with a full path)</p>
<p>For this example running.php is accessed in the browser/cli.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">//included.php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will show running.php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will show included.php</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
//running.php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">INCLUDE</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'included.php'</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/12/16/php-showing-the-name-of-the-current-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SimpleXml save formated output</title>
		<link>http://www.f15ijp.com/2010/12/09/simplexml-save-formated-output/</link>
		<comments>http://www.f15ijp.com/2010/12/09/simplexml-save-formated-output/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 17:35:20 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[DOMElement]]></category>
		<category><![CDATA[PHP4]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[SimpleXML]]></category>
		<category><![CDATA[indentation]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=751</guid>
		<description><![CDATA[When using the SimpleXml->asXML(&#8216;file.xml&#8217;) the output is simply written onto one line. like &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;product&#62;&#60;companyId&#62;1&#60;/companyId&#62;&#60;productId&#62;1:1&#60;/productId&#62;&#60;/product&#62; There is nothing wrong with this but if you add line breaks and indentations the xml file looks better and is easier to (manually) read. Unfortunately there is no way to do this using SimpleXML, but there is [...]]]></description>
			<content:encoded><![CDATA[<p>When using the SimpleXml->asXML(&#8216;file.xml&#8217;) the output is simply written onto one line.<br />
like</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;product<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;companyId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/companyId<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;productId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1:1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/productId<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>There is nothing wrong with this but if you add line breaks and indentations the xml file looks better and is easier to (manually) read.<br />
Unfortunately there is no way to do this using SimpleXML, but there is a quick and dirty way to do this; and that is to import the SimpleXMLobject to a DOMElement and do it there so some example code</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$xmlDom</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dom_import_simplexml</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$simpleXmlObject</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xmlDom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formatOutput</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xmlDom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This would result in an xml file looking like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;companyId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/companyId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;productId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1:1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/productId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Easier to read but takes some extra space on the disk (might not be much but it is good to remember).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/12/09/simplexml-save-formated-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP5: Quick on calling a parents constructor</title>
		<link>http://www.f15ijp.com/2010/11/12/php5-quick-on-calling-a-parents-constructor/</link>
		<comments>http://www.f15ijp.com/2010/11/12/php5-quick-on-calling-a-parents-constructor/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 15:00:28 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHP4]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[extends]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php4]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=703</guid>
		<description><![CDATA[Using OOP there comes a need to call the constructor of a parent class, this is not hard to do class TestParent &#123; public function __construct&#40;&#41; &#123; var_dump&#40;'blah'&#41;; &#125; &#125; &#160; class TestChild extends TestParent &#123; public function __construct&#40;&#41; &#123; parent::__construct&#40;&#41;; &#125; &#125; &#160; $a = new TestChild&#40;&#41;; //Output will be: string 'blah' (length=4) In [...]]]></description>
			<content:encoded><![CDATA[<p>Using OOP there comes a need to call the constructor of a parent class, this is not hard to do</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> TestParent <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blah'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> TestChild <span style="color: #000000; font-weight: bold;">extends</span> TestParent <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TestChild<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Output will be: string 'blah' (length=4)</span></pre></div></div>

<p>In PHP4 this would have looked like (this still works in PHP5)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> TestParent <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TestParent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blah'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> TestChild <span style="color: #000000; font-weight: bold;">extends</span> TestParent <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TestChild<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">TestParent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TestChild<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Output will be: string 'blah' (length=4)</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/11/12/php5-quick-on-calling-a-parents-constructor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento redirect</title>
		<link>http://www.f15ijp.com/2010/10/25/magento-redirect/</link>
		<comments>http://www.f15ijp.com/2010/10/25/magento-redirect/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 10:24:45 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=692</guid>
		<description><![CDATA[Sometimes there is a need to do a redirect from inside a Magento page where you might not know if headers are sent or not &#8211; Or maybe you wish to make a new redirect function where you don&#8217;t have to worry about writing different code if the headers are sent or not. This is [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes there is a need to do a redirect from inside a Magento page where you might not know if headers are sent or not &#8211; Or maybe you wish to make a new redirect function where you don&#8217;t have to worry about writing different code if the headers are sent or not.</p>
<p>This is a way to do a redirect where a javascript redirect is used if headers have been sent (and thus it is no longer possible to use a header redirect)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">headers_sent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getBaseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'portal/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$baseUrl</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getBaseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'portal/'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'&lt;script type=&quot;text/javascript&quot;&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;window.location.href = '<span style="color: #006699; font-weight: bold;">{$baseUrl}</span>';&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'&lt;/script&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And the function <a href="http://php.net/manual/en/function.headers-sent.php">headers_sent()</a> is a php function so that can of course be used outside of Magento in any php scrip where a header location is nice but not always possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/10/25/magento-redirect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML: UTF-8 encoding</title>
		<link>http://www.f15ijp.com/2010/07/14/html-utf-8-encoding/</link>
		<comments>http://www.f15ijp.com/2010/07/14/html-utf-8-encoding/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 13:10:23 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=551</guid>
		<description><![CDATA[To get a html page to display UTF-8 encoded text correctly (without setting a default charset) simply add the following to the head of the html page. &#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=UTF-8&#34; /&#62;]]></description>
			<content:encoded><![CDATA[<p>To get a html page to display UTF-8 encoded text correctly (without <a href="http://www.f15ijp.com/2010/01/14/apache2-changing-charset-using-htaccess/">setting a default charset</a>) simply add the following to the head of the html page.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/07/14/html-utf-8-encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Converting a bool value to a string value</title>
		<link>http://www.f15ijp.com/2010/07/12/php-converting-a-bool-value-to-a-string-value/</link>
		<comments>http://www.f15ijp.com/2010/07/12/php-converting-a-bool-value-to-a-string-value/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 14:30:59 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHP5]]></category>
		<category><![CDATA[bool]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[typecast]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=538</guid>
		<description><![CDATA[The first idea that comes into mind for doing this is to simply make a typecast of the boolean variable to a string and use that (which works) $testVar = false; echo &#40;string&#41;$testVar; //will output a empty string (as that evaluates to false) $testVar = true; echo &#40;string&#41;$testVar; //will output 1 (as that evaluates to [...]]]></description>
			<content:encoded><![CDATA[<p>The first idea that comes into mind for doing this is to simply make a typecast of the boolean variable to a string and use that (which works)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$testVar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$testVar</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will output a empty string (as that evaluates to false)</span>
<span style="color: #000088;">$testVar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$testVar</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will output 1 (as that evaluates to true)</span></pre></div></div>

<p>but what if the requirement is that the string should say true or false</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$testVar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$testVar</span> ? <span style="color: #0000ff;">'true'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'false'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will output false</span>
<span style="color: #000088;">$testVar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$testVar</span> ? <span style="color: #0000ff;">'true'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'false'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will output true</span></pre></div></div>

<p>(While the above example might seam useless I recently had to do this for a db insert)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/07/12/php-converting-a-bool-value-to-a-string-value/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP5: Quick on timing a script</title>
		<link>http://www.f15ijp.com/2010/06/03/php5-quick-on-timing-a-script/</link>
		<comments>http://www.f15ijp.com/2010/06/03/php5-quick-on-timing-a-script/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 09:01:30 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHP5]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=487</guid>
		<description><![CDATA[Sometimes it is nice to know how long a scrip took to execute (or a part of a script). This is a simple way to time a script in php. $time_start = microtime&#40;true&#41;; &#160; usleep&#40;500&#41;; &#160; $time_end = microtime&#40;true&#41;; $time = $time_end - $time_start; &#160; echo &#34;run time was &#34; . $time . &#34; seconds&#34;;]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is nice to know how long a scrip took to execute (or a part of a script).<br />
This is a simple way to time a script in php.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$time_start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">usleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$time_end</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time_end</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$time_start</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;run time was &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$time</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; seconds&quot;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/06/03/php5-quick-on-timing-a-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP5: Quick on exceptions</title>
		<link>http://www.f15ijp.com/2010/01/21/php5-quick-on-exceptions/</link>
		<comments>http://www.f15ijp.com/2010/01/21/php5-quick-on-exceptions/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 18:00:00 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHP5]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://f15ijp.com/?p=201</guid>
		<description><![CDATA[Very quick (&#038;dirty): 1 2 3 4 5 6 7 8 try&#123; doStuff&#40;&#41;; &#125; catch &#40;Exception $e&#41;&#123; echo 'Error on line '. $e-&#62;getLine&#40;&#41;.' in '. $e-&#62;getFile&#40;&#41; . $e-&#62;getMessage&#40;&#41;; //Or if you are working inside an object, you could use. echo 'Error on line '.$this-&#62;getLine&#40;&#41;.' in '.$this-&#62;getFile&#40;&#41; . $e-&#62;getMessage&#40;&#41;; &#125; Now to catch a specific kind [...]]]></description>
			<content:encoded><![CDATA[<p>Very quick (&#038;dirty):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">try<span style="color: #009900;">&#123;</span>
	doStuff<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Error on line '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' in '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//Or if you are working inside an object, you could use.</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Error on line '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' in '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now to catch a specific kind of exception (in this case CustomException), and say woups, but to re-throw all other Exceptions.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">try<span style="color: #009900;">&#123;</span>
	doStuffThatCanGiveCustomException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//echo get_class($e) . &quot;&lt;br/&gt;&quot;;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;CustomException&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">&quot;My custom exception message.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;woups&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #b1b100;">throw</span> <span style="color: #000088;">$e</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>To throw a custom exception:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My exception message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For more informaion about this please check out the <a href="http://www.php.net/manual/en/language.exceptions.php">php manual</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/01/21/php5-quick-on-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

