<?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>Bunkermaster&#039;s PHP Blog &#124; Web Development &#124; Object Oriented &#124; MVC &#124; MySQL &#124; Apache</title>
	<atom:link href="http://blog.bunkermaster.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bunkermaster.com</link>
	<description>Those things I want to share about PHP, MySQL, Apache, CSS, HTML, JQuery and all the other things that make our profession a living nightmare!</description>
	<lastBuildDate>Thu, 12 May 2011 09:05:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Using arrays as constants in PHP by Bunkermaster</title>
		<link>http://blog.bunkermaster.com/php-coding/using-arrays-as-constants-in-php.html</link>
		<comments>http://blog.bunkermaster.com/php-coding/using-arrays-as-constants-in-php.html#comments</comments>
		<pubDate>Sun, 09 Jan 2011 17:56:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[constant]]></category>
		<category><![CDATA[constants]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[readability]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=128</guid>
		<description><![CDATA[Sometimes, I find myself facing a language limitation that baffles me. Generally speaking I never hard code any setting in my code. I extract it all into my precious config file (or my config table, material for another post) so that I can change the inner workings of my code. [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Sometimes, I find myself facing a language limitation that baffles me.</p>
<p>Generally speaking I never hard code any setting in my code. I extract it all into my precious config file (or my config table, material for another post) so that I can change the inner workings of my code. Sometimes those settings come in the form of strings, integers and even arrays of the previously mentioned.</p>
<p>To define an array as a constant you can&#8217;t just define an array as the constant. For some reason PHP doesn&#8217;t allow that.</p>
<pre class="brush: php">&amp;amp;amp;lt;?php
define( &#039;A_CONSTANT_ARRAY&#039; , array( &#039;ONE&#039; =&amp;amp;amp;gt; &#039;ONE&#039; , &#039;TWO&#039; =&amp;amp;amp;gt; &#039;TWO&#039;, &#039;THREE&#039; =&amp;amp;amp;gt; 3)); // won&#039;t work
?&amp;amp;amp;gt;</pre>
<p>So you have to use the serialize function instead. It&#8217;s a simple bypass really since you actually define a string as a constant. That string happens to be a serialized array.</p>
<pre class="brush: php">&amp;amp;amp;lt;?php
define( &#039;A_CONSTANT_ARRAY&#039; , serialize( array( &#039;ONE&#039; =&amp;amp;amp;gt; &#039;ONE&#039; , &#039;TWO&#039; =&amp;amp;amp;gt; &#039;TWO&#039;, &#039;THREE&#039; =&amp;amp;amp;gt; 3))); // will work
?&amp;amp;amp;gt;</pre>
<p>To use it it&#8217;s a simple matter of unserializing the string into a regular array and you can access its values. Now a few questions arises:</p>
<p><em>Q: what&#8217;s the point of using a constant to assign it to a variable later on?</em></p>
<p>The constant is accessible anywhere in your code. No matter how deep you are in your code, you can always access it.</p>
<p><em>Q: How do I access the content of my array?</em></p>
<p>Simply unserialize the constant string into a variable.</p>
<pre class="brush: php">&amp;amp;amp;lt;?php
define( &#039;A_CONSTANT_ARRAY&#039; , serialize( array( &#039;ONE&#039; =&amp;amp;amp;gt; &#039;ONE&#039; , &#039;TWO&#039; =&amp;amp;amp;gt; &#039;TWO&#039;, &#039;THREE&#039; =&amp;amp;amp;gt; 3)));
$some_variable = unserialize( A_CONSTANT_ARRAY );
var_dump( $some_variable );
?&amp;amp;amp;gt;</pre>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/php-coding/using-arrays-as-constants-in-php.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy New Year 2011 from Bunkermaster&#8217;s PHP Blog!</title>
		<link>http://blog.bunkermaster.com/miscellaneous/happy-new-year-2011.html</link>
		<comments>http://blog.bunkermaster.com/miscellaneous/happy-new-year-2011.html#comments</comments>
		<pubDate>Sun, 02 Jan 2011 13:50:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=125</guid>
		<description><![CDATA[I wish you all a happy new year. May 2011 bring joy, happiness, work, love, everything you need! My next topic of discussion: an array as a constant! No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I wish you all a happy new year. May 2011 bring joy, happiness, work, love, everything you need!</p>
<p>My next topic of discussion: an array as a constant!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/miscellaneous/happy-new-year-2011.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Merry Xmas all!</title>
		<link>http://blog.bunkermaster.com/miscellaneous/merry-xmas-all.html</link>
		<comments>http://blog.bunkermaster.com/miscellaneous/merry-xmas-all.html#comments</comments>
		<pubDate>Sat, 25 Dec 2010 14:25:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=122</guid>
		<description><![CDATA[On this christmas day, I&#8217;d like to extend my best wishes to all of you who visit my blog. No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>On this christmas day, I&#8217;d like to extend my best wishes to all of you who visit my blog. </p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/miscellaneous/merry-xmas-all.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The great 127.255.255.255 IP enigma!</title>
		<link>http://blog.bunkermaster.com/php-coding/the-great-127-255-255-255-ip-enigma.html</link>
		<comments>http://blog.bunkermaster.com/php-coding/the-great-127-255-255-255-ip-enigma.html#comments</comments>
		<pubDate>Mon, 23 Aug 2010 08:56:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[127.255.255.255]]></category>
		<category><![CDATA[BIGINT]]></category>
		<category><![CDATA[INT]]></category>
		<category><![CDATA[ip2long]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=120</guid>
		<description><![CDATA[Hi all, few may have noticed I&#8217;ve been rather quiet on my blog lately but I have the best excuse! I&#8217;ve been extremely busy working on an important project. Topic of the day: the weird 127.255.255.255 IP I found in my system&#8217;s access log. I have a MySQL table with [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>few may have noticed I&#8217;ve been rather quiet on my blog lately but I have the best excuse! I&#8217;ve been extremely busy working on an important project.</p>
<p>Topic of the day: the weird 127.255.255.255 IP I found in my system&#8217;s access log.</p>
<p>I have a MySQL table with a signed INT temporarily storing <a title="ip2long on PHP.net" href="http://www.php.net/ip2long" target="_blank">ip2long</a> processed IPs of visitors. The ip2long function converts an IP into a number that can be stored and queried very simply using basic SQL.</p>
<p>The problem is, signed INT can only store numbers between 2147483647 and -2147483647. 2147483647 is trhe numerical representation of the IP 127.255.255.255. This doesn&#8217;t mean that someone from that IP connected to my site. It means that someone with an IP that translated to a higher number connected and I stored it in a too short field.</p>
<p>I altered my INT into a BIGINT and voila!</p>
<p>References:</p>
<p><a title="MySQL Numeric Types" href="http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html" target="_blank">http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html</a></p>
<p><a title="ip2long on PHP.net" href="http://fr2.php.net/ip2long" target="_blank">http://fr2.php.net/ip2long</a></p>
<p>I hope this helps at least one confused fellow developer out there.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/php-coding/the-great-127-255-255-255-ip-enigma.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Converting a String to ROT13 for email obfuscator</title>
		<link>http://blog.bunkermaster.com/php-coding/string-to-rot13-email-obfuscator.html</link>
		<comments>http://blog.bunkermaster.com/php-coding/string-to-rot13-email-obfuscator.html#comments</comments>
		<pubDate>Tue, 23 Feb 2010 23:34:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[obfuscator]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ROT13]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=116</guid>
		<description><![CDATA[A few days ago (weeks? nah) I posted about ROT13 encryption. Since then I&#8217;ve been implementing the JQuery ROT13 email obfuscator. I figured I would reuse my code and just add a string to Hex function. Well it did work and here&#8217;s me sharing with the world. &#60;?php function stringToHex( [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>A few days ago (weeks? nah) I posted about ROT13 encryption. Since then I&#8217;ve been implementing the <a title="JQuery Rotational String Obfuscator" href="http://plugins.jquery.com/project/RotationalStringObfuscator" target="_blank">JQuery ROT13 email obfuscator</a>. I figured I would reuse my code and just add a string to Hex function.</p>
<p>Well it did work and here&#8217;s me sharing with the world.</p>
<pre class="brush: php">&lt;?php
function stringToHex( $dumbString ){
$teh_split = str_split( $dumbString , 1 );
$output = &#039;&#039;;
foreach( $teh_split as $oneLetter ){
$output .= (string) dechex( ord( $oneLetter ));
}
return $output;
}

function HexROT13( $hexedROT13  = &#039;&#039; ){
$rot13_ref = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;;
$rot13_translate = &quot;NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm&quot;;
$teh_split = str_split( $hexedROT13 , 2 );
$teh_ref = str_split( $rot13_ref , 1 );
$teh_translate = str_split( $rot13_translate , 1 );
$output = &#039;&#039;;
foreach( $teh_split as $letter ){
$rot13_char = chr( hexdec( $letter ));
$rot13_index = array_search( $rot13_char , $teh_ref );
if( $rot13_index &gt; 0 ){
$output .= $rot13_translate[ $rot13_index ];
} else {
$output .= $rot13_char;
}
}
return $output;
}

echo HexROT13( stringToHex( &quot;youremail@yourdomain.com&quot; ));
?&gt;</pre>
<p>I know it may solve the problem of encoding into ROT13 from a string for a handful of you guys.</p>
<p>Enjoy!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/php-coding/string-to-rot13-email-obfuscator.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New wordpress theme</title>
		<link>http://blog.bunkermaster.com/miscellaneous/new-wordpress-theme.html</link>
		<comments>http://blog.bunkermaster.com/miscellaneous/new-wordpress-theme.html#comments</comments>
		<pubDate>Wed, 10 Feb 2010 23:19:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=110</guid>
		<description><![CDATA[Well, as time passes and my blog project launch is coming closer (this is not launched, who would&#8217;ve thought?) I have to take a little more interest in the looks of this blog. After spending a rather annoying time looking for the right theme, I found this one. It&#8217;s wide [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Well, as time passes and my blog project launch is coming closer (this is not launched, who would&#8217;ve thought?) I have to take a little more interest in the looks of this blog. After spending a rather annoying time looking for the right theme, I found this one. It&#8217;s wide enough for most of my code examples and it&#8217;s easy to read and navigate.</p>
<p>I hope you guys like it. Soon there will be more posting about development tips and best practices. My current project is well under way and I should have a little more time to share my thoughts.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/miscellaneous/new-wordpress-theme.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hex to ASCII to ROT13 in PHP</title>
		<link>http://blog.bunkermaster.com/php-coding/hex-rot13-php.html</link>
		<comments>http://blog.bunkermaster.com/php-coding/hex-rot13-php.html#comments</comments>
		<pubDate>Fri, 15 Jan 2010 21:49:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ROT13]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=106</guid>
		<description><![CDATA[Couple days ago, a friend posted his status on facebook using a strange code in hexadecimal that didn&#8217;t translate from ASCII. I investigated his little code and BEHOLD! I found the solution. So here is the useless function I made to decode his little prank. &#60;?php function HexROT13( $hexedROT13  = [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Couple days ago, a friend posted his status on facebook using a strange code in hexadecimal that didn&#8217;t translate from ASCII. I investigated his little code and BEHOLD! I found the solution. So here is the useless function I made to decode his little prank.</p>
<pre class="brush: php">&lt;?php

function HexROT13( $hexedROT13  = &#039;&#039; ){
$rot13_ref = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;;
$rot13_translate = &quot;NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm&quot;;
$teh_split = str_split( $hexedROT13 , 2 );
$teh_ref = str_split( $rot13_ref , 1 );
$teh_translate = str_split( $rot13_translate , 1 );
$output = &#039;&#039;;
foreach( $teh_split as $letter ){
$rot13_char = chr( hexdec( $letter ));
$rot13_index = array_search( $rot13_char , $teh_ref );
if( $rot13_index &gt; 0 ){
$output .= $rot13_translate[ $rot13_index ];
} else {
$output .= $rot13_char;
}
}
return $output;
}
echo HexROT13( &#039;516261276720736265747267206762207165766178206c6268652042696e7967766172&#039; );

?&gt;</pre>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/php-coding/hex-rot13-php.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If only I had more time&#8230;</title>
		<link>http://blog.bunkermaster.com/miscellaneous/if-only-i-had-more-time.html</link>
		<comments>http://blog.bunkermaster.com/miscellaneous/if-only-i-had-more-time.html#comments</comments>
		<pubDate>Fri, 15 Jan 2010 21:40:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=104</guid>
		<description><![CDATA[&#8230; I would post more PHP related articles. Sadly (and thankfully) I am overworked at the moment. A big project is taking most of my work time and my free time is divided between sleep and&#8230; Well, OK, I sleep a lot lately. Soon I shall make time to post [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>&#8230; I would post more PHP related articles. Sadly (and thankfully) I am overworked at the moment. A big project is taking most of my work time and my free time is divided between sleep and&#8230; Well, OK, I sleep a lot lately.</p>
<p>Soon I shall make time to post more about readability (with the secret hope to trigger more discussion in comments), some SimpleXML and probably some random tidbits.</p>
<p>I hope you are having a wonderful 2010 so far.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/miscellaneous/if-only-i-had-more-time.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Happy new year!</title>
		<link>http://blog.bunkermaster.com/miscellaneous/happy-new-year.html</link>
		<comments>http://blog.bunkermaster.com/miscellaneous/happy-new-year.html#comments</comments>
		<pubDate>Sun, 03 Jan 2010 20:43:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=100</guid>
		<description><![CDATA[If your calendar year ended 4 days ago, happy new year! I&#8217;m not gone, just resting a bit during the holidays. Soon more PHP related posts. No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If your calendar year ended 4 days ago, happy new year!</p>
<p>I&#8217;m not gone, just resting a bit during the holidays. Soon more PHP related posts.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/miscellaneous/happy-new-year.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Merry Christmas all!</title>
		<link>http://blog.bunkermaster.com/miscellaneous/merry-christmas-all.html</link>
		<comments>http://blog.bunkermaster.com/miscellaneous/merry-christmas-all.html#comments</comments>
		<pubDate>Fri, 25 Dec 2009 11:22:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://blog.bunkermaster.com/?p=98</guid>
		<description><![CDATA[Whether you celebrate Christmas as a religious or a commercial celebration, I wish you all a merry Christmas! And for my fellow trekkers, live long and prosper! No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Whether you celebrate Christmas as a religious or a commercial celebration, I wish you all a merry Christmas!</p>
<p>And for my fellow trekkers, live long and prosper!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bunkermaster.com/miscellaneous/merry-christmas-all.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

