<?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>Steve&#039;s Blog &#187; PHP</title>
	<atom:link href="http://crindigo.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://crindigo.com/blog</link>
	<description>Escapades of a web programmer</description>
	<lastBuildDate>Sun, 18 Sep 2011 04:40:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Ugly Old RPG Code</title>
		<link>http://crindigo.com/blog/2011/07/ugly-old-rpg-code/</link>
		<comments>http://crindigo.com/blog/2011/07/ugly-old-rpg-code/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 23:18:27 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[rpg]]></category>
		<category><![CDATA[vbulletin]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=110</guid>
		<description><![CDATA[Here&#8217;s an example of my past, and how bad I used to be at application design. I started this RPG back in 2006 and eventually stopped making it at the end of 2008. It sort of works&#8230; well, it would &#8230; <a href="http://crindigo.com/blog/2011/07/ugly-old-rpg-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example of my past, and how bad I used to be at application design. I started this RPG back in 2006 and eventually stopped making it at the end of 2008. It sort of works&#8230; well, it would if it included a DB dump (or install script) and you had a vBulletin installation to hook it into. I&#8217;ve apparently lost the latest copy, which included the beginning of a status effect editor, so that feature is missing.</p>
<p>Beginning coders should probably not study this as an example, though I will admit I did some neat algorithms, and the ajax-ified equip screen and battle system are cool.</p>
<p><a href="http://crindigo.com/stuff/rpg-0.5.0.zip">http://crindigo.com/stuff/rpg-0.5.0.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2011/07/ugly-old-rpg-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exception Thrown Without a Stack Frame and Sessions</title>
		<link>http://crindigo.com/blog/2011/03/exception-thrown-without-a-stack-frame-and-sessions/</link>
		<comments>http://crindigo.com/blog/2011/03/exception-thrown-without-a-stack-frame-and-sessions/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 02:48:28 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=104</guid>
		<description><![CDATA[Just a note, if anyone receives this error at the bottom of the page when programming in PHP, and you&#8217;ve checked things like throwing exceptions inside of exception handlers, check any objects you&#8217;re storing in $_SESSION. If an exception is &#8230; <a href="http://crindigo.com/blog/2011/03/exception-thrown-without-a-stack-frame-and-sessions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just a note, if anyone receives this error at the bottom of the page when programming in PHP, and you&#8217;ve checked things like throwing exceptions inside of exception handlers, check any objects you&#8217;re storing in $_SESSION. If an exception is thrown when the session mechanism serializes your objects (usually at the very end of a request), it will be outside of the regular code flow and will spit out an error at the very end of your output.</p>
<p>So, if this applies to you, make sure you do not attempt to serialize properties that cannot be serialized, using __sleep to limit the properties. Then, define a __wakeup to reconstruct those properties if necessary.</p>
<p>Ref: <a href="http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep">http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2011/03/exception-thrown-without-a-stack-frame-and-sessions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Shell Execution Reminder</title>
		<link>http://crindigo.com/blog/2011/01/php-shell-execution-reminder/</link>
		<comments>http://crindigo.com/blog/2011/01/php-shell-execution-reminder/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 19:09:42 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imaging]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=96</guid>
		<description><![CDATA[If you are using PHP to execute a custom-written shell script, keep in mind that the $PATH for the web server&#8217;s user can be different than the user account you&#8217;re using to execute it. Meaning, if it doesn&#8217;t behave properly, &#8230; <a href="http://crindigo.com/blog/2011/01/php-shell-execution-reminder/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are using PHP to execute a custom-written shell script, keep in mind that the $PATH for the web server&#8217;s user can be different than the user account you&#8217;re using to execute it. Meaning, if it doesn&#8217;t behave properly, try using full paths to programs. For example, when writing a shell script to generate thumbnails for JPGs in a directory:</p>
<pre class="brush: bash; title: ; notranslate">
cd $1
for i in `ls | egrep -i '\.jpg$'`; do
    /usr/local/bin/convert $i -thumbnail $2x$3 thumb_$i
done
</pre>
<p>Just using &#8220;convert&#8221; rather than &#8220;/usr/local/bin/convert&#8221; doesn&#8217;t work, since /usr/local/bin is not part of $PATH for the web server.</p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2011/01/php-shell-execution-reminder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ancient Image Class</title>
		<link>http://crindigo.com/blog/2010/06/ancient-image-class/</link>
		<comments>http://crindigo.com/blog/2010/06/ancient-image-class/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 01:33:19 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imaging]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=81</guid>
		<description><![CDATA[This is a really old image library/class thing I wrote back in Summer 2006 while working with Jeremy and his company. I believe it was originally written in PHP4 and updated to PHP5 a month or two after the original &#8230; <a href="http://crindigo.com/blog/2010/06/ancient-image-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a really old image library/class thing I wrote back in Summer 2006 while working with <a href="http://jeremyprivett.com/">Jeremy</a> and his company. I believe it was originally written in PHP4 and updated to PHP5 a month or two after the original was written. There are some features, like drawing rotated images/ellipses, that were commented away due to them not working on PHP4, but may work now if someone dares to try. <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  The comments are fairly plentiful, and I&#8217;m feeling lazy, so it shouldn&#8217;t need a manual to get started (besides, I haven&#8217;t used it in years either).</p>
<p>The code is located at <a href="http://gist.github.com/429474">http://gist.github.com/429474</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/06/ancient-image-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Wildfire Log Adapter for Solar</title>
		<link>http://crindigo.com/blog/2010/05/wildfire-log-adapter-for-solar/</link>
		<comments>http://crindigo.com/blog/2010/05/wildfire-log-adapter-for-solar/#comments</comments>
		<pubDate>Sat, 29 May 2010 05:25:59 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[crindigan]]></category>
		<category><![CDATA[solar]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=74</guid>
		<description><![CDATA[While doing some more development for Crindigan, I figured I should be looking for a better way to show debug information than putting it in the page footer, so I looked at FirePHP. Unfortunately the Firephp log adapter in Solar &#8230; <a href="http://crindigo.com/blog/2010/05/wildfire-log-adapter-for-solar/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While doing some more development for Crindigan, I figured I should be looking for a better way to show debug information than putting it in the page footer, so I looked at FirePHP. Unfortunately the Firephp log adapter in <a href="http://solarphp.com/">Solar</a> was out of date, so I wrote a quick adapter that uses the newer Wildfire protocol.</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Log adapter that works with the latest FirePHP version
 * (probably not FireConsole though, whenever it's released).
 *
 * @package Crindigan
 * @author Steven Harris
 * @license http://opensource.org/licenses/bsd-license.php BSD
 * @version $Id$
 */
class Rpg_Log_Adapter_Wildfire extends Solar_Log_Adapter {

    /**
     * Default configuration values.
     *
     * @config string|array events The event types this instance
     *   should recognize; a comma-separated string of events, or
     *   a sequential array.  Default is all events ('*').
     *
     * @config dependency response A Solar_Http_Response dependency injection.
     *
     * @var array
     *
     */
    protected $_Rpg_Log_Adapter_Wildfire = array(
        'events'   =&gt; '*',
        'response' =&gt; 'response',
    );

    /**
     * The Solar_Http_Response where headers will be sent.
     *
     * @var Solar_Http_Response
     */
    protected $_response;

    /**
     * The Solar_Json instance used to encode JSON for Wildfire.
     *
     * @var Solar_Json
     */
    protected $_json;

    /**
     * Wildfire header index to keep headers in sequential order.
     *
     * @var int
     */
    protected $_index = 0;

    /**
     * Post-construction tasks. Sets up the response, JSON, and default Wildfire headers.
     */
    protected function _postConstruct() {
        parent::_postConstruct();

        $this-&gt;_response = Solar::dependency('Solar_Http_Response', $this-&gt;_config['response']);

        $this-&gt;_json = Solar::factory('Solar_Json');

		$this-&gt;_response-&gt;setHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
        $this-&gt;_response-&gt;setHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3');
        $this-&gt;_response-&gt;setHeader('X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
    }

    /**
     * Writes the log message to FirePHP.
     *
     * @param  string $class Class name.
     * @param  string $event Event name.
     * @param  mixed  $descr Log data. Any data type should work, assuming it can be encoded as JSON.
     * @return bool Always true.
     */
    protected function _save($class, $event, $descr) {
    	$meta = array();
    	$meta['Type']  = 'LOG';
    	$meta['Label'] = &quot;$class-$event&quot;;

    	$data = $this-&gt;_json-&gt;encode(array($meta, $descr));
    	$len  = strlen($data);

		if ( strlen($data) &lt;= 4990 ) {
			$this-&gt;_index++;
			$this-&gt;_response-&gt;setHeader(&quot;X-Wf-1-1-1-{$this-&gt;_index}&quot;, &quot;$len|$data|&quot;);
		} else {
			$chunks = chunk_split($data, 4990, &quot;\n&quot;);
			$parts = explode(&quot;\n&quot;, $chunks);
            $num_parts = count($parts);
            for ( $i = 0; $i &lt; $num_parts; $i++ ) {
				$this-&gt;_index++;
				$this-&gt;_response-&gt;setHeader(&quot;X-Wf-1-1-1-{$this-&gt;_index}&quot;,
					($i == 0 ? $len : '') . &quot;|{$parts[$i]}|&quot; . (($i == $num_parts - 1) ? '' : '\\'));
            }
        }

        return true;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/05/wildfire-log-adapter-for-solar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pwiff Update</title>
		<link>http://crindigo.com/blog/2010/02/pwiff-update/</link>
		<comments>http://crindigo.com/blog/2010/02/pwiff-update/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 05:36:36 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pwiff]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=69</guid>
		<description><![CDATA[I just committed a simple Movie and Encoder class, so making a blank movie is now far easier to understand. At least now you don&#8217;t have to calculate the file length by hand. The first step is to define an &#8230; <a href="http://crindigo.com/blog/2010/02/pwiff-update/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just committed a simple Movie and Encoder class, so making a blank movie is now far easier to understand. At least now you don&#8217;t have to calculate the file length by hand. <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<pre class="brush: php; title: ; notranslate">
$env = new Pwiff_Environment;
$env-&gt;setSwfVersion(10);

$movie = new Pwiff_Movie($env);
$movie-&gt;setFrameSize(100, 100);
$movie-&gt;setFrameRate(0);

$enc = new Pwiff_Encoder($movie, new Pwiff_Output_File('test.swf'));
$enc-&gt;encode();
</pre>
<p>The first step is to define an environment, which creates a context for encoding (and later decoding). By setting the version, certain tags or tag attributes could be ignored when reading or writing, if they are in a higher version than what you set. Then, you define a movie object, and set some of its properties, like the frame size and frame rate. After that, you would do more fancy things (when they get written, though you can addTag() with it right now). Finally, set up an encoder, passing the movie and output objects, and call encode(), which will write it with the given output instance (in this case, to the file test.swf).</p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/02/pwiff-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pwiff Source Released</title>
		<link>http://crindigo.com/blog/2010/02/pwiff-source-released/</link>
		<comments>http://crindigo.com/blog/2010/02/pwiff-source-released/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 04:28:05 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pwiff]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=66</guid>
		<description><![CDATA[Today, I was able to get Pwiff to create a &#8220;blank&#8221; SWF file, meaning a header, a FileAttributes tag, and an End tag. As a result, I decided to start a Google Code project for it, and host the files &#8230; <a href="http://crindigo.com/blog/2010/02/pwiff-source-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today, I was able to get Pwiff to create a &#8220;blank&#8221; SWF file, meaning a header, a FileAttributes tag, and an End tag. As a result, I decided to start a Google Code project for it, and host the files there instead of my private subversion location. It&#8217;s very bare bones right now, as you can see from the following example that created the 25-byte file:</p>
<pre class="brush: php; title: ; notranslate">
$env = new Pwiff_Environment;
$env-&gt;setSwfVersion(10);

$out = new Pwiff_Output_File('test.swf');

$h = new Pwiff_Record_Header(false, 10, 25, new Pwiff_Record_Rect(0, 100, 0, 100), 0, 0);
$f = new Pwiff_Tag_FileAttributes($env);
$e = new Pwiff_Tag_End($env);

$h-&gt;write($out);
$f-&gt;write($out);
$e-&gt;write($out);
</pre>
<p>So yeah, it definitely needs some helper classes to be easier to use. <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' />  Right now it&#8217;s pretty much just raw record/tag classes. The resulting SWF file is located <a href="/stuff/test.swf">here</a>.</p>
<p><a href="http://code.google.com/p/pwiff/">Pwiff @ Google Code</a><br />
<a href="http://ohloh.net/p/pwiff">Pwiff @ Ohloh</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/02/pwiff-source-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NextShout is now Free</title>
		<link>http://crindigo.com/blog/2010/02/nextshout-is-now-free/</link>
		<comments>http://crindigo.com/blog/2010/02/nextshout-is-now-free/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 04:00:03 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[nextshout]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=63</guid>
		<description><![CDATA[NextShout was a commercial shoutbox product I released two or three years ago, for the vBulletin forum software. Its bandwidth consumption is far lower than any competing products, due to its use of efficient JSON and only sending information deltas, &#8230; <a href="http://crindigo.com/blog/2010/02/nextshout-is-now-free/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>NextShout was a commercial shoutbox product I released two or three years ago, for the vBulletin forum software. Its bandwidth consumption is far lower than any competing products, due to its use of efficient JSON and only sending information deltas, rather than completely refreshing entire blocks of HTML. Other features include a modular command system, multiple channels, automatic pruning and logging (configurable per channel), and new post/thread notices. It requires PHP 5.1.4, and at least vBulletin 3.6.9 (currently unavailable for 4.x).</p>
<p>Find more information and the download <a href="/nextshout/">at its website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/02/nextshout-is-now-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing Pwiff</title>
		<link>http://crindigo.com/blog/2010/02/introducing-pwiff/</link>
		<comments>http://crindigo.com/blog/2010/02/introducing-pwiff/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 05:36:32 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pwiff]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=59</guid>
		<description><![CDATA[Considering I&#8217;ve reached a small milestone in the project, I figured I would write a post explaining what I&#8217;ve been up to. My previous entry relates to this, as at the time I was experimenting with writing a class to &#8230; <a href="http://crindigo.com/blog/2010/02/introducing-pwiff/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Considering I&#8217;ve reached a small milestone in the project, I figured I would write a post explaining what I&#8217;ve been up to. My previous entry relates to this, as at the time I was experimenting with writing a class to encode binary data into a stream of bits. Float information was important, as the class needed to support half-precision floating point numbers, which standard PHP cannot do.</p>
<p>If the name of the project didn&#8217;t give it away, I am writing an SWF output (possibly input, later) library using only PHP, without the need for something like ext/ming or swflib. The name seems pretty unoriginal &#8211; SWF is pronounced <i>swiff</i>, so I put a P in there for PHP <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> . The last project which attempted this, <a href="http://sf.net/projects/freemovie/">FreeMovie</a>, has not been updated in more than five years, was written in PHP4, and crammed into a few large files. This one is written using the PHP5 object model, and will hopefully be modular enough to extend upon as the SWF specification continues to grow.</p>
<p>Currently, there is a class for writing out the raw datatypes, and a set of classes for the current SWF records (RGB, RGBA, ARGB, LanguageCode, Matrix, Rect, CXForm, and CXFormWithAlpha). I have other issues/work occupying my time at the moment, but after I get back into this, I plan on starting a Google Code project for it once it can actually encode a full SWF file.</p>
<p>Until next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/02/introducing-pwiff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extracting Information from Floats</title>
		<link>http://crindigo.com/blog/2010/01/extracting-information-from-floats/</link>
		<comments>http://crindigo.com/blog/2010/01/extracting-information-from-floats/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 03:34:58 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=54</guid>
		<description><![CDATA[I was tinkering around with working in binary again, for a project I may or may not follow through on &#8211; still deciding. Along the way I was dealing with floating point numbers, and how to work with their individual &#8230; <a href="http://crindigo.com/blog/2010/01/extracting-information-from-floats/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was tinkering around with working in binary again, for a project I may or may not follow through on &#8211; still deciding. Along the way I was dealing with floating point numbers, and how to work with their individual bits in PHP. It&#8217;s definitely not as nice as in C, where you can just typecast into the raw binary representation. Unless there&#8217;s a better way I haven&#8217;t seen, you have to pack() a float, then unpack() it as an unsigned int, before you can use bitwise operators on it to pick out information.</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Takes a single-precision floating point number, and returns it as a
 * sequence of bits in the form of an unsigned integer.
 *
 * @param  float $float
 * @return int
 */
function floatToIntBits($float)
{
	$s = unpack('Vval', pack('f', $float));
	return $s['val'];
}

/**
 * Takes a sequence of bits representing a float in the form of an unsigned
 * integer, and returns an associative array of information about the float.
 *
 * The returned array has the keys:
 * - sign: 0 if positive, 1 if negative
 * - exp:  exponent, with 127 exponent bias applied
 * - mant: decoded mantissa
 *
 * Using these you can reconstruct the float with (1 - 2*sign) * mant * 2^exp
 *
 * @param  int $bits
 * @return array
 */
function floatInfo($bits)
{
	$exponent = ($bits &amp; 0x7f800000) &gt;&gt; 23;
	$mantissa = $bits &amp; 0x7fffff;

	// if the exponent is nonzero, the mantissa gets a leading bit
	if ($exponent !== 0) {
		$mantissa |= 1 &lt;&lt; 23;
	}

	// decode the mantissa
	// bit 23 = 1.0
	// bit 22 = 0.5
	// bit 21 = 0.25
	// etc
	$decoded = 0;
	for ($i = 23; $i &gt;= 0; $i--) {
		if (($mantissa &gt;&gt; $i) &amp; 1) {
			$decoded += pow(2, $i - 23);
		}
	}

	return array(
		// sign would otherwise be -1 on 32bit systems
		'sign' =&gt; abs(($bits &amp; 0x80000000) &gt;&gt; 31),
		'exp'  =&gt; $exponent - 127,
		'mant' =&gt; $decoded,
	);
}

$bits = floatToIntBits(25.0);
var_dump(floatInfo($bits));
// array(3) {
//   [&quot;sign&quot;]=&gt;
//   int(0)
//   [&quot;exp&quot;]=&gt;
//   int(4)
//   [&quot;mant&quot;]=&gt;
//   float(1.5625)
// }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/01/extracting-information-from-floats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

