<?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>Compiled Thoughts by John Ciacia &#187; PHP</title>
	<atom:link href="http://www.johnciacia.com/category/snippets/php-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johnciacia.com</link>
	<description>Science, Technology, and Beyond</description>
	<lastBuildDate>Fri, 06 Jan 2012 15:46:22 +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>Get Trending Topics from Twitter</title>
		<link>http://www.johnciacia.com/2011/07/03/get-trending-topics-from-twitter/</link>
		<comments>http://www.johnciacia.com/2011/07/03/get-trending-topics-from-twitter/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 04:29:41 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=1281</guid>
		<description><![CDATA[I recently had the need to get the trending topics on Twitter, and discovered it was really easy. Below is the code: [code]$url = &#34;http://api.twitter.com/1/trends/1.json&#34;; $data = json_decode(file_get_contents($url)); print_r($data); [/code]]]></description>
			<content:encoded><![CDATA[<p>I recently had the need to get the trending topics on Twitter, and discovered it was really easy. Below is the code:</p>
<p>[code]$url = &quot;http://api.twitter.com/1/trends/1.json&quot;;<br />
$data = json_decode(file_get_contents($url));<br />
print_r($data);<br />
[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2011/07/03/get-trending-topics-from-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bogosort</title>
		<link>http://www.johnciacia.com/2011/05/27/bogosort/</link>
		<comments>http://www.johnciacia.com/2011/05/27/bogosort/#comments</comments>
		<pubDate>Sat, 28 May 2011 00:47:41 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Crappy Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=1018</guid>
		<description><![CDATA[PHP implementation of *Bogosort *I hope no one will actually use this.]]></description>
			<content:encoded><![CDATA[<p>PHP implementation of <a href="http://en.wikipedia.org/wiki/Bogosort">*Bogosort</a></p>
<p><script src="https://gist.github.com/996463.js"> </script></p>
<p>*I hope no one will <strong>actually</strong> use this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2011/05/27/bogosort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic OCR</title>
		<link>http://www.johnciacia.com/2010/01/04/basic-ocr/</link>
		<comments>http://www.johnciacia.com/2010/01/04/basic-ocr/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 03:40:11 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[gd]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=454</guid>
		<description><![CDATA[This is a very basic optical character recognition script written in PHP. This is untested and serves merely a proof of concept. As noted in the comments, adjusting the sample size can improve results, since with a large sample size on a small image there can be many collisions. A database is needed to compare [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very basic optical character recognition script written in PHP. This is untested and serves merely a proof of concept. As noted in the comments, adjusting the sample size can improve results, since with a large sample size on a small image there can be many collisions. A database is needed to compare output results of this script with known values.</p>
<p>[code lang="PHP"]<?php</p>
<p>/* create a test image */<br />
$im = @imagecreate(100, 20) or die("Cannot Initialize new GD image stream");<br />
$background_color = imagecolorallocate($im, 255, 255, 255);<br />
$text_color = imagecolorallocate($im, 0, 0, 0);<br />
imagestring($im, 1, 5, 5,  "Hello, World!", $text_color);</p>
<p>/***<br />
 * Assumptions:<br />
 *   A monochrome image where characters are black<br />
 *   A single character is connected<br />
 *   Characters are disjointed by white space<br />
 */</p>
<p>$width = imagesx($im);<br />
$height = imagesy($im);</p>
<p>/***<br />
 * Notes:<br />
 *   The smaller the sample size the more accurate it will be,<br />
 *   however, it will take longer. Larger images can use a larger<br />
 *   sample size wihtout compromizing much accuracy.<br />
 */<br />
$x_sample = 1;<br />
$y_sample = 1;</p>
<p>$last = 0;<br />
for($i = 0; $i < $width; $i++) {<br />
    $col = array();</p>
<p>    for($j = 0; $j < $height; $j++) {<br />
        $col[$j] = imagecolorat($im, $i, $j);<br />
    }</p>
<p>    if(($current = array_sum($col)) > 0) {<br />
        if($last == 0) {<br />
            $l = 0;<br />
        }</p>
<p>        for($k = 0; $k < $height; $k++) {<br />
            if(($l % $x_sample) == 0) {<br />
                if(($k % $y_sample) == 0) {<br />
                    $sample .= $col[$k];<br />
                }<br />
            }<br />
        }</p>
<p>        $l++;<br />
        $last = $current;<br />
    } else {<br />
        $last = 0;<br />
    }</p>
<p>    if(!empty($sample) &#038;&#038; $last == 0) {<br />
        echo $sample . "\n";<br />
        $sample = "";<br />
    }<br />
}<br />
?>[/code]</p>
<p>Output (each line represents a character)</p>
<div class="quote">00000011111100000000000000001000000000000000000010000000000000000011111100000000<br />
00000000011000000000000000001011000000000000000011010000000000000000010100000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
00000000011000000000000000001001000000000000000010010000000000000000011000000000<br />
000000000001000000000000000001100000000000000000010000000000<br />
00000011111100000000000000000110000000000000000001100000000000000011111100000000<br />
00000000011000000000000000001001000000000000000010010000000000000000011000000000<br />
00000000111100000000000000000100000000000000000010000000000000000000010000000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
00000000011000000000000000001001000000000000000010100000000000000011111100000000<br />
00000001110100000000</div>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/04/basic-ocr/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using PHP and GD to add border to text</title>
		<link>http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/</link>
		<comments>http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 23:41:03 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[image border]]></category>
		<category><![CDATA[imagettf]]></category>
		<category><![CDATA[stroke]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[text border]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=449</guid>
		<description><![CDATA[[code lang="PHP"][/code]]]></description>
			<content:encoded><![CDATA[<p>[code lang="PHP"]<?php<br />
/**<br />
 * Writes the given text with a border into the image using TrueType fonts.<br />
 * @author John Ciacia<br />
 * @param image An image resource<br />
 * @param size The font size<br />
 * @param angle The angle in degrees to rotate the text<br />
 * @param x Upper left corner of the text<br />
 * @param y Lower left corner of the text<br />
 * @param textcolor This is the color of the main text<br />
 * @param strokecolor This is the color of the text border<br />
 * @param fontfile The path to the TrueType font you wish to use<br />
 * @param text The text string in UTF-8 encoding<br />
 * @param px Number of pixels the text border will be<br />
 * @see http://us.php.net/manual/en/function.imagettftext.php<br />
 */<br />
function imagettfstroketext(&#038;$image, $size, $angle, $x, $y, &#038;$textcolor, &#038;$strokecolor, $fontfile, $text, $px) {</p>
<p>    for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)<br />
        for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)<br />
            $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);</p>
<p>   return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);<br />
} [/code]</p>
<p>[code lang="PHP"]<?php<br />
$img = imagecreatefrompng("/home/john/Desktop/test.png");<br />
$font_color = imagecolorallocate($img, 0, 0, 0);<br />
$stroke_color = imagecolorallocate($img, 255, 0, 0);<br />
imagettfstroketext($img, 10, 0, 10, 50, $font_color, $stroke_color, "abstract.ttf", "Hello, World!", 2);<br />
?>[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Basic CAPTCHA</title>
		<link>http://www.johnciacia.com/2010/01/04/basic-captcha/</link>
		<comments>http://www.johnciacia.com/2010/01/04/basic-captcha/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 23:01:18 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[gd]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=443</guid>
		<description><![CDATA[Very basic code demonstrating the use of the GD library by creating a simple CAPTCHA. [code lang="PHP"][/code]]]></description>
			<content:encoded><![CDATA[<p>Very basic code demonstrating the use of the GD library by creating a simple CAPTCHA.<br />
[code lang="PHP"]<?php<br />
function randomString($length){<br />
    $pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";<br />
    if(empty($length)){<br />
        $length = "10";<br />
    }</p>
<p>    for($i=0; $i<$length; $i++){<br />
        $string .= $pattern{rand(0,61)};<br />
    }</p>
<p>    return $string;<br />
}</p>
<p>function captcha() {<br />
    header("Content-type: image/png");<br />
    $im = @imagecreate(100, 50) or die("Cannot Initialize new GD image stream");<br />
    $background_color = imagecolorallocate($im, 0, 0, 0);<br />
    $text_color = imagecolorallocate($im, 255, 0, 0);<br />
    $string = randomString();<br />
    imagestring($im, 10, 5, 5,  $string, $text_color);<br />
    imagepng($im);<br />
    imagedestroy($im);<br />
}</p>
<p>captcha();<br />
?>[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/04/basic-captcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tic Tac Toe</title>
		<link>http://www.johnciacia.com/2009/05/22/tic-tac-toe/</link>
		<comments>http://www.johnciacia.com/2009/05/22/tic-tac-toe/#comments</comments>
		<pubDate>Sat, 23 May 2009 00:34:31 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[tic tac toe]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=163</guid>
		<description><![CDATA[A graphical Tic Tac Toe board using PHP-Gtk [code]#!/usr/local/bin/php -q]]></description>
			<content:encoded><![CDATA[<p>A graphical Tic Tac Toe board using PHP-Gtk<br />
[code]#!/usr/local/bin/php -q<br />
<?php<br />
class TicTacToe extends GtkWindow{</p>
<p>	private $_buttons;<br />
	private $_dialog;<br />
	private $_count;<br />
	private $_menu;<br />
	private $_lbl;</p>
<p>	public function __construct()<br />
	{<br />
		parent::__construct();</p>
<p>		$this->set_title('Tic-Tac-Toe');<br />
		$this->set_size_request(250, 250);<br />
		$this->set_position(Gtk::WIN_POS_CENTER);<br />
		$this->connect_simple('destroy', array('gtk', 'main_quit'));</p>
<p>		#Create the Buttons and add them to the table<br />
		for($i = 0; $i < 9; $i++) {<br />
		    $this->_buttons[$i] = new GtkButton('');<br />
		    $this->_buttons[$i]->connect_simple('clicked', array($this, 'clicked'), $i);<br />
		}</p>
<p>		#Create a GtkTable<br />
		$tbl = new GtkTable(3, 3);</p>
<p>		#Add nine buttons to the table<br />
		for($i = 0; $i < 9; $i++) {<br />
		    $tbl->attach($this->_buttons[$i], ($i%3), ($i%3)+1, floor($i/3), floor($i/3)+1);<br />
		}</p>
<p>		$this->buildMenu();</p>
<p>        #GtkStatusBar<br />
        $status = new GtkStatusbar();<br />
        $context = array('Not Connected', 'Connected');<br />
		$status->push($status->get_context_id($context[0]), $context[0]);</p>
<p>		#GtkVBox<br />
		$vbox = new GtkVBox();<br />
		#Add the GtkVBox to the main window<br />
		$this->add($vbox);<br />
		#Add the GtkMenu to the GtkVBox<br />
		$vbox->pack_start($this->_menu, false);<br />
		#Add the GtkTable to the GtkVBox<br />
		$vbox->pack_start($tbl, true, true);<br />
		#Add the GtkStatusBar to the GtkVBox<br />
		$vbox->pack_start($status, false);</p>
<p>		$this->show_all();</p>
<p>		$this->server();</p>
<p>	}</p>
<p>	private function server()<br />
	{<br />
        #Not implemented<br />
	}</p>
<p>	private function buildMenu()<br />
	{<br />
		#GtkMenu<br />
		$this->_menu = new GtkMenuBar();<br />
		$this->_menu->append($file_item = new GtkMenuItem('_File'));<br />
        $this->_menu->append($help_item = new GtkMenuItem('_Help'));</p>
<p>		$file_item->set_submenu($file_menu = new  GtkMenu());<br />
        $file_menu->append($file_new_item = new GtkMenuItem('_New'));<br />
        $file_menu->append($file_connect_item = new GtkMenuItem('_Connect'));<br />
        $file_menu->append($file_quit_item = new GtkMenuItem('_Quit'));</p>
<p> 		$help_item->set_submenu($help_menu = new  GtkMenu());<br />
		$help_menu->append($help_about_item = new GtkMenuItem('_About'));</p>
<p>        $file_new_item->connect_simple('activate', array($this,'restart'));<br />
        $help_about_item->connect_simple('activate', array($this,'about'));<br />
        $file_quit_item->connect_simple('activate', array('Gtk','main_quit'));<br />
	}</p>
<p>	public function about()<br />
	{<br />
		$about = new GtkAboutDialog();<br />
		$about->set_authors(array("John Ciacia"));<br />
		$about->set_comments("Tic-Tac-Toe created using the PHP-Gtk extension.");<br />
		$about->set_copyright("Copyright (C) 2008 John Ciacia");<br />
		$about->set_license("This software is released under the GNU GPL");<br />
		$about->set_version("1.0");<br />
		$about->set_website("http://www.codecall.net");<br />
		$about->set_website_label("http://www.codecall.net");<br />
		$about->show_all();<br />
	}</p>
<p>	public function clicked($i)<br />
	{<br />
		!isset($this->_count) ? $this->_count = 0 : $this->_count++;<br />
		($this->_count % 2 == 0) ? $this->_lbl = 'X' : $this->_lbl = 'O';</p>
<p>		$this->_buttons[$i]->set_label($this->_lbl);<br />
        $this->_buttons[$i]->set_sensitive(false);</p>
<p>        $this->_check();<br />
	}</p>
<p>	private function _check()<br />
	{<br />
	    $win = false;</p>
<p>        $combinations = array(<br />
            0 => array(0, 1, 2),<br />
            1 => array(3, 4, 5),<br />
            2 => array(6, 7, 8),</p>
<p>            3 => array(0, 3, 6),<br />
            4 => array(1, 4, 7),<br />
            5 => array(2, 5, 8),</p>
<p>            6 => array(0, 4, 8),<br />
            7 => array(2, 4, 6));</p>
<p>        for($i = 0; $i < 8; $i++)<br />
        {<br />
            if( ($this->_buttons[$combinations[$i][0]]->get_label() ==<br />
                    $this->_buttons[$combinations[$i][1]]->get_label()) &#038;&#038; </p>
<p>                ($this->_buttons[$combinations[$i][1]]->get_label() ==<br />
                    $this->_buttons[$combinations[$i][2]]->get_label()) &#038;&#038; </p>
<p>                ($this->_buttons[$combinations[$i][0]]->get_label() != "")){</p>
<p>                $win = true;<br />
            }<br />
        }</p>
<p>	    if($win) {<br />
	        $this->end_dialog(true);<br />
	    }<br />
	    else if(!$win &#038;&#038; $this->_count == <img src='http://www.johnciacia.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> {<br />
	        $this->end_dialog();<br />
	    }<br />
	    else {<br />
	    	;<br />
	    }<br />
	}</p>
<p>	private function end_dialog($win = false){</p>
<p>		$this->_dialog = new GtkDialog(null, $this);<br />
		$this->_dialog->set_title("Play Again?");<br />
		$this->_dialog->set_default_size('100','100');<br />
		$this->_dialog->set_modal(true);<br />
		$this->_dialog->set_transient_for($this);<br />
		$this->_dialog->set_resizable(false);<br />
		$this->_dialog->connect_simple('destroy', array($this, 'destroy'));<br />
		if($win) {<br />
		    $label = new GtkLabel($this->_lbl . " has won the game. Play again?");<br />
		} else {<br />
			$label = new GtkLabel("It's a tie! Play again?");<br />
		}<br />
		$button_yes = new GtkButton('_Yes');<br />
		$button_yes->connect_simple('clicked', array($this, 'restart'));<br />
		$button_no = new GtkButton('_No');<br />
		$button_no->connect('clicked', array($this, 'destroy'));</p>
<p>		$vbox1 = $this->_dialog->vbox;<br />
		$vbox2 = $this->_dialog->action_area;<br />
		$vbox1->pack_start($label);<br />
		$vbox2->pack_start($button_yes);<br />
		$vbox2->pack_start($button_no);<br />
		$this->_dialog->show_all();<br />
	}</p>
<p>	public function restart()<br />
	{<br />
		if(isset($this->_dialog)) { $this->_dialog->hide_all(); }<br />
		unset($this->_count);</p>
<p>		foreach($this->_buttons as $button):<br />
			$button->set_label('');<br />
			$button->set_sensitive(true);<br />
		endforeach;<br />
	}</p>
<p>    public function destroy()<br />
    {<br />
    	echo "Good Bye!\n";<br />
        Gtk::main_quit();<br />
    }</p>
<p>}</p>
<p>new TicTacToe();<br />
Gtk::main();</p>
<p>?>[/code]</p>
<p><a href="http://www.johnciacia.com/wp-content/uploads/2009/05/tictactoe.png"><img src="http://www.johnciacia.com/wp-content/uploads/2009/05/tictactoe-300x187.png" alt="tictactoe" title="tictactoe" width="300" height="187" class="aligncenter size-medium wp-image-164" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2009/05/22/tic-tac-toe/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Email Obfuscator</title>
		<link>http://www.johnciacia.com/2009/05/22/email-obfuscator/</link>
		<comments>http://www.johnciacia.com/2009/05/22/email-obfuscator/#comments</comments>
		<pubDate>Sat, 23 May 2009 00:25:21 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[obfuscator]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=156</guid>
		<description><![CDATA[[code lang="Javascript"] [/code]]]></description>
			<content:encoded><![CDATA[<p>[code lang="Javascript"]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></p>
<p><script type="text/javascript">
//<![CDATA[
window.onload = function () {
	geo();
}</p>
<p>function geo() {
	if (!document.getElementsByTagName) // Check for browser support
			return false;
	if (rot13)
		var map = rot13init(); </p>
<p>    var links = document.getElementsByTagName('a');</p>
<p>    function geo_decode(anchor) {
        var href = anchor.getAttribute('href');
        var address = href.replace(/.*contact\/([a-z0-9._%-]+)\+([a-z0-9._%-]+)\+([a-z.]+)/i, '$1' + '@' + '$2' + '.' + '$3');
        var linktext = anchor.innerHTML;
            if (href != address) {
                anchor.setAttribute('href','mailto:' + (rot13 ? str_rot13(address,map) : address)); // Add mailto link	
                anchor.innerHTML = linktext; // IE Fix
        }
    }</p>
<p>    for (var l = 0 ; l < links.length ; l++)
    {
        links[l].onclick = function()
        {
            geo_decode(this);
        }</p>
<p>        links[l].onmouseover = function()
        {
                geo_decode(this);</p>
<p>        }
    }
}</p>
<p>var rot13 = 1;</p>
<p>function rot13init() {
	var map = new Array();
	var s = "abcdefghijklmnopqrstuvwxyz";
	for (var i = 0 ; i < s.length ; i++)
		map[s.charAt(i)] = s.charAt((i+13)%26);
	for (var i = 0 ; i < s.length ; i++)
		map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
	return map;
}</p>
<p>function str_rot13(a,map) {
	var s = "";
	for (var i = 0 ; i < a.length ; i++) {
		var b = a.charAt(i);
		s += (b>='A' &#038;&#038; b<='Z' || b>='a' &#038;&#038; b<='z' ? map[b] : b);
	}
	return s;
}
//]]&gt;
</script><br />
</head></p>
<p><body><br />
<?php</p>
<p>function cloakmail($content) {</p>
<p>	preg_match_all("^[-a-z-A-Z-0-9\._]+@[-a-z-A-Z-0-9\._]+\.[a-z]{2,4}^", $content, $emails);</p>
<p>	for($i = 0; $i < count($emails[0]); $i++) {<br />
		$username = explode("@", $emails[0][$i]);<br />
		$domain = explode(".", str_rot13($username[1]));</p>
<p>		if(count($domain) > 2) {<br />
			$replace = '<a href="contact/' . str_rot13($username[0]) . '+'<br />
			. $domain[0] . '+'<br />
			. $domain[1] . '.'<br />
			. $domain[2] .'" rel="nofollow">' . asc2html($emails[0][$i]) . '</a>';<br />
		} else {<br />
			$replace = '<a href="contact/' . str_rot13($username[0]) . '+'<br />
			. $domain[0] . '+'<br />
			. $domain[1] .'" rel="nofollow">' . asc2html($emails[0][$i]) . '</a>';<br />
		}</p>
<p>		$content = str_replace($emails[0][$i], $replace, $content);<br />
	}</p>
<p>	return $content;<br />
}</p>
<p>function asc2html($email) {<br />
	$html = "";<br />
	$len = strlen($email);<br />
	for($i = 0; $i < $len; $i++) {<br />
		$html .= "&#" . ord($email[$i]);<br />
	}<br />
	return $html;<br />
}</p>
<p>$content = "Sidewinder@anything.extreme-hq.com<br />\n<br />
Sidewinder@extreme-hq.com";</p>
<p>echo cloakmail($content);<br />
?><br />
</body><br />
</html>[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2009/05/22/email-obfuscator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binary to Decimal Conversion</title>
		<link>http://www.johnciacia.com/2009/05/21/133/</link>
		<comments>http://www.johnciacia.com/2009/05/21/133/#comments</comments>
		<pubDate>Thu, 21 May 2009 05:08:00 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[decimal]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=133</guid>
		<description><![CDATA[Converts a binary number to its decimal equivalent. However unlike the bindec function, this will preserve the binary/radix point. Code [code] [/code] Usage [code]echo bin2dec ( "1011101.1000101", true ); [/code] Output [code]1 + 4 + 8 + 16 + 64 + 0.5 + 0.03125 + 0.0078125 = 93.5390625[/code] Usage [code]echo bin2dec ( "1011101.1000101"); [/code] Output [...]]]></description>
			<content:encoded><![CDATA[<p>Converts a binary number to its decimal equivalent. However unlike the <a href="http://us3.php.net/manual/en/function.bindec.php">bindec </a>function, this will preserve the <a href="http://en.wikipedia.org/wiki/Binary_point">binary/radix point</a>.</p>
<p><strong>Code</strong><br />
[code]<?php</p>
<p>/**<br />
 * Convert a binary number with our without<br />
 * a radix point to its decimal equivalent.<br />
 *<br />
 * @param $binary The binary number to convert.<br />
 * @param $output Show the calculations.<br />
 * @return The decimal conversion<br />
 */<br />
function bin2dec($binary, $output = false) {<br />
    $N = 0;<br />
    $o = "";<br />
    list ( $rhs, $lhs ) = explode ( ".", $binary );<br />
    $rhs = strrev ( $rhs );<br />
    for($i = 0; $i < strlen ( $rhs ); $i ++) {<br />
        $d = $rhs [$i] * pow ( 2, $i );<br />
        $N = $d + $N;<br />
        $o = ($d == 0) ? $o : $o . $d . " + ";<br />
    }</p>
<p>    for($i = 0; $i < strlen ( $lhs ); $i ++) {<br />
        $d = $lhs [$i] * pow ( 2, - ($i + 1) );<br />
        $N = $d + $N;<br />
        $o = ($d == 0) ? $o : $o . $d . " + ";<br />
    }</p>
<p>    return ($output) ? substr ( $o, 0, - 3 ) . " = " . $N : $N;<br />
}</p>
<p>?> [/code]</p>
<p><strong>Usage</strong><br />
[code]echo bin2dec ( "1011101.1000101", true );  [/code]<br />
<strong>Output</strong><br />
[code]1 + 4 + 8 + 16 + 64 + 0.5 + 0.03125 + 0.0078125 = 93.5390625[/code]<br />
<strong>Usage</strong><br />
[code]echo bin2dec ( "1011101.1000101");  [/code]<br />
<strong>Output</strong><br />
[code]93.5390625[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2009/05/21/133/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.johnciacia.com @ 2012-02-05 10:00:26 -->
