<?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; php</title>
	<atom:link href="http://www.f15ijp.com/tag/php/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>Installing PHPUnit on ubuntu</title>
		<link>http://www.f15ijp.com/2011/02/07/installing-phpunit-on-ubuntu/</link>
		<comments>http://www.f15ijp.com/2011/02/07/installing-phpunit-on-ubuntu/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 12:19:31 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=772</guid>
		<description><![CDATA[The installation package that can be installed from apt includes a console tool to run PHPUnits, but is (currently) not the latest version. One way to get past this is to install PHPUnit from apt and then upgrade PHPUnit via PEAR note: (currently) PEAR needs to be updated as well. user@devserver~: sudo apt-get install phpunit [...]]]></description>
			<content:encoded><![CDATA[<p>The installation package that can be installed from apt includes a console tool to run PHPUnits, but is (currently) not the latest version. One way to get past this is to install PHPUnit from apt and then upgrade PHPUnit via PEAR note: (currently) PEAR needs to be updated as well.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>devserver~: <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> phpunit
user<span style="color: #000000; font-weight: bold;">@</span>devserver~: <span style="color: #c20cb9; font-weight: bold;">sudo</span> pear channel-discover pear.phpunit.de
user<span style="color: #000000; font-weight: bold;">@</span>devserver~: <span style="color: #c20cb9; font-weight: bold;">sudo</span> pear channel-discover components.ez.no
user<span style="color: #000000; font-weight: bold;">@</span>devserver~: <span style="color: #c20cb9; font-weight: bold;">sudo</span> pear channel-discover pear.symfony-project.com
user<span style="color: #000000; font-weight: bold;">@</span>devserver~: <span style="color: #c20cb9; font-weight: bold;">sudo</span> pear update
user<span style="color: #000000; font-weight: bold;">@</span>devserver~: <span style="color: #c20cb9; font-weight: bold;">sudo</span> pear update phpunit<span style="color: #000000; font-weight: bold;">/</span>PHPUnit</pre></div></div>

<p>The line that simply says &#8220;sudo pear update&#8221; updates pear to the latest version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2011/02/07/installing-phpunit-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>2</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>OpenX INSERT_RANDOM_NUMBER_HERE example in php</title>
		<link>http://www.f15ijp.com/2010/10/20/openx-insert_random_number_here-example-in-php/</link>
		<comments>http://www.f15ijp.com/2010/10/20/openx-insert_random_number_here-example-in-php/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 08:30:29 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[OpenX]]></category>
		<category><![CDATA[INSERT_RANDOM_NUMBER_HERE]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=687</guid>
		<description><![CDATA[For iframe&#8217;s and noscript tags OpenX uses a random string in the image in order to prevent user caching of banners (as that would mean less impressions and possibly outdated ads). However these tags needs to be added by the user. An example way to make these random numbers using PHP would be to use [...]]]></description>
			<content:encoded><![CDATA[<p>For iframe&#8217;s and noscript tags OpenX uses a random string in the image in order to prevent user caching of banners (as that would mean less impressions and possibly outdated ads).<br />
However these tags needs to be added by the user.<br />
An example way to make these random numbers using PHP would be to use</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>So an complete example invocation code would be</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;a href=&quot;http://www.example.com/ck.php?n=3798N2&amp;cb=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; _fcksavedurl=&quot;http://www.example.com/ck.php?n=3798N2&amp;cb=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; _fcksavedurl=&quot;http://www.example.com/ck.php?n=3798N2&amp;cb=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; 
&lt;img src=&quot;http://www.example.com/avw.php?zoneid=10&amp;n=3798N2&amp;cb=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;/a&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/10/20/openx-insert_random_number_here-example-in-php/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>
	</channel>
</rss>

