<?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>~ overflow ~ &#187; Coding</title>
	<atom:link href="http://www.overflow.biz/blog/lang/en-us/category/tips-hints/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.overflow.biz/blog</link>
	<description>Coding and Internet Randomness</description>
	<lastBuildDate>Sun, 08 Jan 2012 23:34:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en-us</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Convert Object to Array in php</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/12/29/convert-object-to-array-in-php?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=convert-object-to-array-in-php</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/12/29/convert-object-to-array-in-php#comments</comments>
		<pubDate>Wed, 29 Dec 2010 12:29:19 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[toarray]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=518</guid>
		<description><![CDATA[Problem:
How to convert a generic object into an array?
Solution:
I&#8217;ve wrote this to convert simple xml objects into array, works pretty good.

function toArray($obj) {
	if (is_object($obj))
		$obj = (array)$obj;

	if (is_array($obj)) {
		foreach ($obj as &#38;$val)
			$val = toArray($val);
	} else { // if this is not an array so it's a string
		$obj = (string)$obj;
	}

	return $obj;
}

]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong><br />
How to convert a generic object into an array?</p>
<p><strong>Solution:</strong><br />
I&#8217;ve wrote this to convert simple xml objects into array, works pretty good.</p>
<pre class="brush: php;">
function toArray($obj) {
	if (is_object($obj))
		$obj = (array)$obj;

	if (is_array($obj)) {
		foreach ($obj as &#38;$val)
			$val = toArray($val);
	} else { // if this is not an array so it's a string
		$obj = (string)$obj;
	}

	return $obj;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/12/29/convert-object-to-array-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>email validator snippet</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/12/04/email-validator-snippet?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=email-validator-snippet</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/12/04/email-validator-snippet#comments</comments>
		<pubDate>Sat, 04 Dec 2010 19:27:34 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[validate]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=515</guid>
		<description><![CDATA[Problem:
How to validate an email using php?
Solution:
I&#8217;m posting this function because i made it to have older php compatibility.

function email_validator($email) {
	return function_exists(&#34;filter_var&#34;) ?
			filter_var($email, FILTER_VALIDATE_EMAIL)
		: // if filter_var is not defined (php &#60; 5.2), we will emulate php's core here
			!empty($email) &#38;&#38; strlen($email) &#60;= 320 &#38;&#38;
			/**
			 * preg info:
			 *
			 * Copyright © Michael Rushton 2009-10
			 * [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>How to validate an email using php?</p>
<p><strong>Solution:</strong></p>
<p>I&#8217;m posting this function because i made it to have older php compatibility.</p>
<pre class="brush: php;">
function email_validator($email) {
	return function_exists(&#34;filter_var&#34;) ?
			filter_var($email, FILTER_VALIDATE_EMAIL)
		: // if filter_var is not defined (php &#60; 5.2), we will emulate php's core here
			!empty($email) &#38;&#38; strlen($email) &#60;= 320 &#38;&#38;
			/**
			 * preg info:
			 *
			 * Copyright © Michael Rushton 2009-10
			 * http://squiloople.com/
			 *
			 * more at: http://svn.php.net/viewvc/php/php-src/trunk/ext/filter/logical_filters.c?view=markup
			 */
			preg_match(&#34;/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)&#124;(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)&#124;(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)&#124;(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]&#124;(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)&#124;(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]&#124;(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)&#124;(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)&#124;(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})&#124;(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))&#124;(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)&#124;(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])&#124;(?:2[0-4][0-9])&#124;(?:1[0-9]{2})&#124;(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])&#124;(?:2[0-4][0-9])&#124;(?:1[0-9]{2})&#124;(?:[1-9]?[0-9]))){3}))\\]))$/iD&#34;, $email)
	;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/12/04/email-validator-snippet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL full database search</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/12/04/mysql-full-database-search?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mysql-full-database-search</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/12/04/mysql-full-database-search#comments</comments>
		<pubDate>Sat, 04 Dec 2010 18:47:12 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=511</guid>
		<description><![CDATA[Problem:
You need to find a entry or a specific value that&#8217;s into a table from a database, but you don&#8217;t know what is the table neither the database for sure.
Solution:
Use my happy mysql full database search script.
It&#8217;s so fun when all you gotta do is type a single command.
download mysql full database search script
]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>You need to find a entry or a specific value that&#8217;s into a table from a database, but you don&#8217;t know what is the table neither the database for sure.</p>
<p><strong>Solution:</strong></p>
<p>Use my happy mysql full database search script.<br />
It&#8217;s so fun when all you gotta do is type a single command.</p>
<p><a href='http://www.overflow.biz/blog/wp-content/uploads/2010/12/mysql_full_database_search.rar'>download mysql full database search script</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/12/04/mysql-full-database-search/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVN folder cleaning (svn wipe)</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/12/04/svn-folder-cleaning-svn-wipe?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=svn-folder-cleaning-svn-wipe</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/12/04/svn-folder-cleaning-svn-wipe#comments</comments>
		<pubDate>Sat, 04 Dec 2010 13:37:07 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[wipe]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=509</guid>
		<description><![CDATA[Problem:
You did a svn checkout on this nice project but now you don&#8217;t want that .svn folders all over the place, after all you won&#8217;t be commiting it. Suddenly you find out that there&#8217;s thousands of folders with thousands of files.
Solution:
I wrote this little php cli script to fix this:

&#60;?php

// (c) z3n - R1V1@101203 - [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>You did a svn checkout on this nice project but now you don&#8217;t want that .svn folders all over the place, after all you won&#8217;t be commiting it. Suddenly you find out that there&#8217;s thousands of folders with thousands of files.</p>
<p><strong>Solution:</strong></p>
<p>I wrote this little php cli script to fix this:</p>
<pre class="brush: php;">
&#60;?php

// (c) z3n - R1V1@101203 - www.overflow.biz - rodrigo.orph@gmail.com

function _o($msg) {
	echo &#34;\r&#34; . substr($msg,0, 79) . str_repeat(&#34; &#34;, 79 - strlen($msg));
}

function rddir($dir) { /* v2.17 */
	global $tfile,$tdir;

	if (is_dir($dir)) {
		if ($dh = opendir($dir)) {
			while (($file = readdir($dh)) !== false) {
				if ($file != &#34;.&#34; &#38;&#38; $file != &#34;..&#34;) {
					if (is_dir($dir . $file))
						$tdir[] = $dir . $file;
					else
						$tfile[] = $file;
				}
			}
			closedir($dh);
		}
	}
}

if (!isset($argv[1]))
	die(&#34;Usage: &#34; . $_SERVER['PHP_SELF'] . &#34; &#60;path/to/svn_root/&#62;&#34;);

// browse dirs searching for .svn

for (
	$tdir = array($argv[1]),
	$tfile = array(),
	$svn = array(),
	$i = 0;$i &#60; count($tdir);$i++)
{
	rddir($tdir[$i]);
	_o(&#34;Reading: &#34;.$tdir[$i].&#34; ...&#34;);

	foreach ($tfile as $entry) {
		if ($entry != &#34;.&#34; &#38;&#38; $entry != &#34;..&#34;) {
			$fn = $tdir[$i] . (PHP_OS == &#34;WINNT&#34; ? &#34;\\&#34; : &#34;/&#34;) . $entry;
			if ($entry == &#34;.svn&#34; &#38;&#38; !in_array($fn, $svn))
				$svn[] = $fn;

			if (is_dir($fn) &#38;&#38; $entry != &#34;.svn&#34;)
				$tdir[] = $fn;
		}
	}

	$tfile = array();
}

_o(&#34;Found: &#34; . count($svn) . &#34; .svn folders, collecting files...&#34;);

$files = array();
$dirs = array();
$t = 0;

// collect files from .svn folders

foreach ($svn as $dir) {
	for ($tdir = array($dir), $tfile = array(),$i = 0;$i &#60; count($tdir);$i++) {
		rddir($tdir[$i]);
		_o(&#34;[&#34; . $t . &#34;] - Collecting: &#34;. $tdir[$i] .&#34;...&#34;);

		foreach ($tfile as $entry) {
			if ($entry != &#34;.&#34; &#38;&#38; $entry != &#34;..&#34;) {
				$fn = $tdir[$i] . (PHP_OS == &#34;WINNT&#34; ? &#34;\\&#34; : &#34;/&#34;) . $entry;
				$t++;

				if (is_dir($fn)) {
					$tdir[] = $fn;
					$dirs[] = $fn;
				} else {
					$files[] = $fn;
				}
			}
		}
	}
}

$i = count($files) + count($dirs) + count($svn);

// delete files

foreach ($files as $file) {
	_o(&#34;[&#34; . $i . &#34;] Deleting Files: &#34; . $file);
	unlink($file);
	$i--;
}

// delete subfolders

rsort($dirs);

foreach ($dirs as $dir) {
	_o(&#34;[&#34; . $i . &#34;] Deleting Dir: &#34; . $dir);
	rmdir($dir);
	$i--;
}

// delete root .svn folders

foreach ($svn as $dir) {
	_o(&#34;[&#34; . $i . &#34;] Deleting Roots: &#34; . $dir);
	rmdir($dir);
	$i--;
}

echo &#34;\nDone!&#34;;

?&#62;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/12/04/svn-folder-cleaning-svn-wipe/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memcached PHP Class</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/11/21/memcached-php-class?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=memcached-php-class</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/11/21/memcached-php-class#comments</comments>
		<pubDate>Sun, 21 Nov 2010 22:48:52 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=507</guid>
		<description><![CDATA[Problem:
I needed a realiable memcached php class. I know there should be a bunch of them around, but i wanted to write my own anyway, just for fun maybe.
Solution:

&#60;?php

/**
 * WSA Memcached
 *
 * @category Class
 * @package  WSA/Memcached/
 * @author   Rodrigo Moraes Orph &#60;rodrigo.orph@gmail.com&#62;
 * @license  Copyright 2010 http://www.overflow.biz
 * [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>I needed a realiable memcached php class. I know there should be a bunch of them around, but i wanted to write my own anyway, just for fun maybe.</p>
<p><strong>Solution:</strong></p>
<pre class="brush: php;">
&#60;?php

/**
 * WSA Memcached
 *
 * @category Class
 * @package  WSA/Memcached/
 * @author   Rodrigo Moraes Orph &#60;rodrigo.orph@gmail.com&#62;
 * @license  Copyright 2010 http://www.overflow.biz
 * @version  1.01
 * @note     This is a standalone script, it will be able to work without all the
 *           rest of WSA framework.
 */

interface iWSAMemcached {
	public function set($key, $val);
	public function get($key);
	public function delete($key);
	public function increment($key);
	public function decrement($key);
	public function flush();
	public function debug($bool);
	public function addServer($host, $port);
}

class WSAMemcached implements iWSAMemcached {
	/**
	 * Memcache_id key prefix
	 * Will by applied to all memcache fetch/save related functions
	 *
	 * @string
	 */
	public $key_prefix;

	/**
	 * Always serialize a set string
	 * This will also speed up get function by avoiding is_serialized function
	 *
	 * @bool default true
	 */
	public $always_serialize = true;

	/**
	 * Default Expiration Time of a set in seconds
	 *
	 * @int default 86400
	 */
	public $expires = 86400;

	/**
	 * Connection Max Retries
	 * Sets a limit to retry when connection fails
	 *
	 * @int default 10
	 */
	public $max_retry = 10;

	/**
	 * Connection Retry Delay
	 * Sets the delay in ms between connection retries
	 *
	 * @int default 2500
	 */
	public $retry_delay = 2500;

	/**
	 * Connection Timeout in seconds
	 *
	 * @int default 30
	 */
	public $timeout = 30;

	/**
	 * Enables Persistent Connection Mode
	 *
	 * @bool default false
	 */
	public $pmode = false;

	/**
	 * Change key process hash algorithm
	 *
	 * @string hash() compatible algo default md5 (eg: md5 , sha1 , crc32 , haval160 etc)
	 */
	public $key_hash = &#34;md5&#34;;

	/**
	 * Connected Flag
	 *
	 * @bool default true
	 */
	protected $connected = false;

	/**
	 * Memcached object
	 *
	 * @object memcache
	 */
	protected $memcache;

	/**
	 * Memcached host
	 *
	 * @string
	 */
	protected $host;

	/**
	 * Memcached port
	 *
	 * @int
	 */
	protected $port;

	/**
	 * Current retry number
	 *
	 * @int
	 */
	private $retry = 0;

	/**
	 * Constructor
	 *
	 * @param $host string memcached host
	 * @param $port int memcached port
	 * @opt param $key_prefix string memcached key prefix
	 */
	public function __construct($host, $port, $key_prefix = &#34;&#34;) {
		$this-&#62;host = $host;
		$this-&#62;port = $port;
		$this-&#62;key_prefix = $key_prefix;
	}

	/**
	 * Destruct
	 *
	 * Will try to gracefully close memcached connection
	 */
	public function __destruct() {
		$this-&#62;close();
	}

	/**
	 * Add Server to memcache cluster
	 *
	 * @requires memcache 2.0.0+
	 *
	 * @param $host string memcached host
	 * @param $port int memcached port
	 *
	 * @return $bool
	 */
	public function addServer($host, $port, $persistent = true, $weight = 0, $timeout = 1, $retry_interval = 15, $status = false, $failure_callback = null) {
		return $this-&#62;memcache-&#62;addServer(
			$host,
			$post,
			$persistent,
			$weight,
			$timeout,
			$retry_interval,
			$status,
			$failure_callback
		);
	}

	/**
	 * Stores a value on memcache
	 *
	 * @param $key string memcache key
	 * @param $val mixed value to be stored
	 * @opt param $flag mixed memcache flag
	 * @opt param $expires int cache expiration in seconds
	 *
	 * @return bool
	 */
	public function set($key, $val, $flag = MEMCACHE_COMPRESSED, $expires = 0, $no_serialize = false) {
		if (empty($expires) &#124;&#124; intval($expires) &#60;= 0)
			$expires = $this-&#62;expires;

		$this-&#62;connect();

		// check key
		if (empty($key))
			throw new Expection(&#34;Empty key when setting a value&#34;, 2);

		// encode key
		$key = $this-&#62;key_process($key);

		// make sure val is a valid entry
		if (!$no_serialize &#38;&#38; ($this-&#62;always_serialize &#124;&#124; is_array($val)))
			$val = serialize($val);

		return $this-&#62;memcache-&#62;set($key, $val, $flag, $expires);
	}

	/**
	 * Fetches a value on memcache
	 *
	 * @param $key string memcache key
	 *
	 * @return mixed serialized values will be unserialized automatically
	 */
	public function get($key, $no_unserialize = false) {
		if (empty($key))
			throw new Expection(&#34;Empty key when fetching a value&#34;, 3);

		$this-&#62;connect();

		// encode key
		$key = $this-&#62;key_process($key);

		// fetch value
		$val = $this-&#62;memcache-&#62;get($key);

		if (!$no_unserialize &#38;&#38; ($this-&#62;always_serialize &#124;&#124; $this-&#62;is_serialized($val)))
			return unserialize($val);
		else
			return $val;
	}

	/**
	 * Deletes a vlue from memcache
	 *
	 * @param $key string memcache key
	 * @opt param $timeout int delete timeout
	 * @note timeout don't work with memcached version i've tested.
	 *
	 * @return bool delete result
	 */
	public function delete($key, $timeout = 0) {
		if (empty($key))
			throw new Expection(&#34;Empty key when deleting a value&#34;, 5);

		if (empty($timeout) &#124;&#124; intval($timeout) &#60;= 0)
			$timeout = 1;

		$this-&#62;connect();

		// encode key
		$key = $this-&#62;key_process($key);

		// delete value
		return $this-&#62;memcache-&#62;delete($key); //, $timeout);
	}

	/**
	 * Increment a int value
	 *
	 * @param $key string memcache key
	 *
	 * @return int current value
	 */
	public function increment($key, $val = 1) {
		if (empty($key))
			throw new Expection(&#34;Empty key when incrementing a value&#34;, 5);

		if (empty($val))
			$val = 1;

		$this-&#62;connect();

		// encode key
		$key = $this-&#62;key_process($key);

		// increment value
		return $this-&#62;memcache-&#62;increment($key, abs($val));
	}

	/**
	 * Increment a int value
	 *
	 * @param $key string memcache key
	 *
	 * @return int current value
	 */
	public function decrement($key, $val = 1) {
		if (empty($key))
			throw new Expection(&#34;Empty key when decrementing a value&#34;, 6);

		if (empty($val))
			$val = 1;

		$this-&#62;connect();

		// encode key
		$key = $this-&#62;key_process($key);

		// increment value
		return $this-&#62;memcache-&#62;decrement($key, abs($val));
	}

	/**
	 * Flush - Mark all entries as expired
	 *
	 * @return bool
	 */
	public function flush() {
		$this-&#62;connect();

		return $this-&#62;memcache-&#62;flush();
	}

	/**
	 * Debug - Enables/Disables Memcache debug mode
	 *
	 * @note This is a global function
	 *
	 * @return bool
	 */
	public function debug($bool) {
		return memcache_debug($bool ? &#34;on&#34; : &#34;off&#34;);
	}

	/**
	 * Main memcache connector
	 * Will try to connect to memcached, on fail retries a specified number of
	 * times with a configurable delay between attempts; If a connection is
	 * already established will return it's state (bool);
	 *
	 * @return bool
	 */
	protected function connect() {
		if (!$this-&#62;connected) {
			$this-&#62;memcache = new Memcache();

			// connect to memcache
			if ($this-&#62;pmode)
				$ret = $this-&#62;memcache-&#62;pconnect($this-&#62;host, $this-&#62;port, $this-&#62;timeout);
			else
				$ret = $this-&#62;memcache-&#62;connect($this-&#62;host,  $this-&#62;port, $this-&#62;timeout);

			if (!$ret &#38;&#38; $this-&#62;retry &#60; $this-&#62;max_retry) {
				$this-&#62;retry++;
				usleep($this-&#62;retry_delay);
				return $this-&#62;connect();
			} elseif (!$ret) {
				throw new Exception(&#34;Unable to connect to memcached - Tried: &#34;.$this-&#62;max_retry.&#34; times&#34;, 1);
			}

			$this-&#62;connected = $ret;
			return $this-&#62;connected;
		}
	}

	/**
	 * Main memcache connection close
	 *
	 * @return bool
	 */
	protected function close() {
		if ($this-&#62;connected) {
			$this-&#62;memcache-&#62;close();
			$this-&#62;connected = false;
			$this-&#62;memcache = null;

			return true;
		}

		return false;
	}

	/**
	 * Process a key value adding prefix and encoding it to a suitable hash
	 *
	 * @param $key string key value
	 *
	 * @return encoded key value
	 */
	protected function key_process($key) {
		if (empty($key))
			throw new Expection(&#34;Empty key when processing key.&#34;, 4);

		return hash($this-&#62;key_hash, $this-&#62;key_prefix.$key);
	}

	/**
	 * Checks if a variable is serialized
	 *
	 * @param $val mixed
	 * @opt param &#38;$result bool return value
	 *
	 * @return bool
	 */
	protected function is_serialized($value, &#38;$result = null) {
		// Bit of a give away this one
		if (!is_string($value)) {
			return false;
		}

		// Serialized false, return true. unserialize() returns false on an
		// invalid string or it could return false if the string is serialized
		// false, eliminate that possibility.
		if ($value === 'b:0;') {
			$result = false;
			return true;
		}

		$length = strlen($value);
		$end = '';

		switch ($value[0]) {
			case 's':
				if ($value[$length - 2] !== '&#34;') {
					return false;
				}
			case 'b':
			case 'i':
			case 'd':
				// This looks odd but it is quicker than isset()ing
				$end .= ';';
			case 'a':
			case 'O':
				$end .= '}';

			if ($value[1] !== ':') {
				return false;
			}

			switch ($value[2]) {
				case 0:
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 9:
				break;

				default:
					return false;
			}
			case 'N':
				$end .= ';';

				if ($value[$length - 1] !== $end[0]) {
					return false;
				}
			break;

			default:
				return false;
		}

		if (($result = @unserialize($value)) === false) {
			$result = null;
			return false;
		}
		return true;
	}
}
</pre>
<p><strong>More:</strong></p>
<p><a href="http://www.phpclasses.org/package/6631-PHP-Memcached-Class.html" target="_blank">PHPClasses.org Project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/11/21/memcached-php-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking eval and base64 php &#8220;encrypt&#8221;</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/11/17/hacking-eval-and-base64-php-encrypt?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=hacking-eval-and-base64-php-encrypt</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/11/17/hacking-eval-and-base64-php-encrypt#comments</comments>
		<pubDate>Wed, 17 Nov 2010 10:00:05 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ecrypt]]></category>
		<category><![CDATA[encode]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[reverse engineering]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=501</guid>
		<description><![CDATA[Problem:
There are some paranoid coders that nest many eval + base64 one inside the other in order to protect the code. This is not a real ecrypt method, just a lame way to avoid users from removing the annyoing banner by the cost or overloading the server.
example of this type of scheme:

&#60;?php eval(gzinflate(base64_decode('DZbHsqRYEkR/pXddZSxINFhPTxlaa81m7CY6E63h6+ftw3xx3CPC//z3P3+mZvqrPED3q37aoerAVv56g7Uk8f8VZT4W5a+/hQggyx6r7LFHVJLJeq5/q2LyaNXPeiQZG214mBKO3/XtUwEMwzvsJCYDd3EFYHIps+NByYiC7k3fNEOA249etYeRYNjt+/bqV9PH9t4SodpQemOi7fJHwyoCI5X+5zHNQ1BItfskwcnGsApP0glEui2i0OBZtvL9fqdEsSkSI9zJ29cRLlliDmSc0IS9QSOK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))); ?&#62;

Solution:
I wrote [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>There are some paranoid coders that nest many eval + base64 one inside the other in order to protect the code. This is not a real ecrypt method, just a lame way to avoid users from removing the annyoing banner by the cost or overloading the server.</p>
<p>example of this type of scheme:</p>
<pre class="brush: php;">
&#60;?php eval(gzinflate(base64_decode('DZbHsqRYEkR/pXddZSxINFhPTxlaa81m7CY6E63h6+ftw3xx3CPC//z3P3+mZvqrPED3q37aoerAVv56g7Uk8f8VZT4W5a+/hQggyx6r7LFHVJLJeq5/q2LyaNXPeiQZG214mBKO3/XtUwEMwzvsJCYDd3EFYHIps+NByYiC7k3fNEOA249etYeRYNjt+/bqV9PH9t4SodpQemOi7fJHwyoCI5X+5zHNQ1BItfskwcnGsApP0glEui2i0OBZtvL9fqdEsSkSI9zJ29cRLlliDmSc0IS9QSOKolZm4bSxqS1Wo4VXW+vSfpfYxEJxxzMivV7mzr1GeB7zvrLumPQYQ4kryUKsQfqs8t1llujDJGoyfCg1/lfej7S6DZqQm5+5LDL2Ouef5HykumQi9sWi+yVjQKwhMddtzBLBsPo7kKb6M7w56jmKUk4DrO/Mcp2cBI0YpHga8ul2BAT3tkiI9Zr8rfrGjAmIdWW7vltXCL1c/fUD59vFpSNXdHmj5GBrX/nO1ldluWsNguWuJHU+KZRlzIToiZ69RL5mFrt1AxiSxLGRM9UDyP6g/QddWHQ8J9sVq6/2iPFRSBtiV61rIE8kkOvw3Ru04fkTR7qvT23W0hqnqOv3mgCmlpVkXCqDpAOK0qtNN6t7/iThLOJfZUpSuOynLmLlS79cSYyXtOHwrmaHx2o2kpyI/DoHWT0vpJeRahQ588NmBnLFmp27UsekjsYF73nROcey9hkqqf5KtHvlZgMiMSosr/uDko2NHol1TvKFWjTXFkqUnLKLRqG2F90pO4XFglJvX5lnFmJMLX0ToCKNbKnRrNdsZ55fqMm3PdiApfaH2TTF4tn3J1j4cWyDct69BiQyQ+wiuXVRtwb2fOqc+zRKJa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SxTBUarwzhTr5JiBz875cWavW8g5FJFUreiUDqjPZ75Tam/PxDVDdvR6noi3UI8iEToySCtUCItjKkPOLKNX9PkRSoFUs9mgqx7OXLEHUI2ZHLZQyY3QudPX59zdrZ+fvFG0q3+WyRT7fmhZB6Z0LbihCpOp1n4XsbhxOweJkEGYSoRqZyanzVnD2P+OKva1lYLuHOcUXPh6+zR5jc3BzLll0GHnporrjAL+Hq8tDEcF6d9H7rEPFVfa44RRDlB90kBmJM4DkRbD/mnbOJBM+7O2QBi4he6UPmjkLv6yMJekDmSTZD/tCRXoAQiLMlVfhGC8id6mHF72SZf2SnXqZLLEqNznVBc6/L5XFjM5X4hdiv5Nsp9XvzCeOMhE/B3wPWihKIGQwHvZDqm80HLyHrjuYaQqIOOFTr5fgVaqrsZmyOEDn/46AAwxQDwTlcwRgBBQ7Mnf/++/fv37//+evPT4f6Pw=='))); ?&#62;
</pre>
<p><strong>Solution:</strong></p>
<p>I wrote a little function for this before, to break reviewitonline.net&#8217;s &#8220;protection&#8221;. Now i have a full class with better handling and able to decode subfolders.</p>
<p>There you go:</p>
<pre class="brush: php;">
&#60;?php

// (c) z3n - R1V1@100503 - www.overflow.biz - rodrigo.orph@gmail.com

class eval_hack {
	protected $temp;
	protected $dest;

	protected $tdir = array();
	protected $tfile = array();

	protected $ext = array(&#34;php&#34;);

	public function __construct($folder, $temp = &#34;temp/&#34;, $dest = &#34;decoded/&#34;) {

		$this-&#62;o(&#34;(c) z3n - R1V1@100503 - www.overflow.biz - rodrigo.orph@gmail.com&#34;);

		$this-&#62;temp = $temp;
		$this-&#62;dest = $dest;

		if ($this-&#62;check())
			$this-&#62;process($folder);

	}

	protected function check() {
		if (file_exists($this-&#62;temp) &#38;&#38; is_writable($this-&#62;temp)) {
			if (file_exists($this-&#62;dest) &#38;&#38; is_writable($this-&#62;dest)) {
				return true;
			} else {
				$this-&#62;o(&#34;Destination path (&#34;.$this-&#62;dest.&#34;) is not writable / don't exists&#34;);
			}
		} else {
			$this-&#62;o(&#34;Temp path (&#34;.$this-&#62;temp.&#34;) is not writable / don't exists&#34;);
		}

		return false;
	}

	protected function save($fn, $content) {
		$fn = $this-&#62;dest . $fn;
		@ mkdir (dirname($fn), 0777, true);
		return file_put_contents($fn, $content);
	}

	protected function process($folder) {
		if (file_exists($folder) &#38;&#38; is_readable($folder)) {
			for ($this-&#62;tdir[0] = $folder, $i = 0;$i &#60; count($this-&#62;tdir);$i++) {
				$this-&#62;o(&#34;Processing: &#34;.$this-&#62;tdir[$i].&#34;...&#34;);
				$this-&#62;rddir($this-&#62;tdir[$i]);

				for ($j = 0,$k = count($this-&#62;tfile), $this-&#62;o(&#34;Found: &#34;.$k.&#34; files&#34;);$j &#60; $k;$j++) {
					$fn = $this-&#62;tdir[$i] . &#34;/&#34; . $this-&#62;tfile[$j];
					if (file_exists($fn) &#38;&#38; !is_dir($fn) &#38;&#38; filesize($fn) &#62; 0) {
						$ext = strtolower(substr($fn,strrpos($fn,&#34;.&#34;)-strlen($fn)+1));
						if (in_array($ext,$this-&#62;ext)) {
							$this-&#62;o(&#34;Decoding: &#34;.$fn);
							$str = $this-&#62;decode(file_get_contents($fn));
							if ($str === false) {
								$this-&#62;o(&#34;Error decoding: &#34;.$fn);
							} else { // save file to new path
								$this-&#62;save($fn, $str);
							}
						}
					} elseif (is_dir($fn) &#38;&#38; $this-&#62;tfile[$j] != &#34;.&#34; &#38;&#38; $this-&#62;tfile[$j] != &#34;..&#34;) {
						$this-&#62;tdir[] = $fn;
					}
				}

				$this-&#62;tfile = array();
			}

		} else {
			$this-&#62;o(&#34;Process path (&#34;.$folder.&#34;) is invalid&#34;);
		}
	}

	protected function rddir($dir) { /* v2.17-OO */
		if (is_dir($dir)) {
			if ($dh = opendir($dir)) {
				while (($file = readdir($dh)) !== false) {
					if ($file != &#34;.&#34; &#38;&#38; $file != &#34;..&#34;) {
						if (is_dir($dir . $file))
							$this-&#62;tdir[] = $dir . $file;
						else
							$this-&#62;tfile[] = $file;
					}
				}
				closedir($dh);
			}
		}
	}

	public function decode($x, $cut_crap = true) {
		/**
		 * @param $x string with the file
		 * @return false &#124; string
		 */

		for ($i = 0;strpos($x,&#34;eval(&#34;) !== false;$i++) {
			$this-&#62;o(&#34;.&#34;, false);
			file_put_contents($this-&#62;temp . &#34;x&#34; . $i . &#34;.php&#34;,str_replace(&#34;eval(&#34;,&#34;file_put_contents('&#34;.$this-&#62;temp.&#34;y&#34;.$i.&#34;.php',&#34;,$x));
			exec(&#34;php &#34;.$this-&#62;temp.&#34;x&#34;.$i.&#34;.php&#34;);
			unlink($this-&#62;temp . &#34;x&#34;.$i.&#34;.php&#34;);
			if ($i &#62; 0)
				unlink($this-&#62;temp . &#34;y&#34;.($i - 1).&#34;.php&#34;);

			$x = file_get_contents($this-&#62;temp . &#34;y&#34;.$i.&#34;.php&#34;);
		}

		$this-&#62;o($i . &#34; nested&#34;);

		if (file_exists($this-&#62;temp . &#34;y&#34;. ($i - 1).&#34;.php&#34;)) {
			unlink($this-&#62;temp . &#34;y&#34; . ($i - 1) . &#34;.php&#34;);

			if ($cut_crap) {
				if (substr($x, 0, 7) == &#34;?&#62;&#60;?php&#34;)
					$x = substr($x, 2);

				if (substr($x, -4) == &#34;?&#62;&#60;?&#34;)
					$x = substr($x, 0, -4);
			}

			return $x;
		} else {
			return false;
		}
	}

	private function o($msg, $nl = true) {
		echo $msg.($nl ? &#34;\n&#34; : &#34;&#34;);
	}

}

if (php_sapi_name() != &#34;cli&#34;)
	die(&#34;You must run this on CLI&#34;);

if (!isset($argv[1]))
	die(&#34;Usage: &#34;.$_SERVER['PHP_SELF'].&#34; &#60;folder/to/hack/&#62; [temp folder] [destination folder]&#34;);

$hack = new eval_hack($argv[1], isset($argv[2]) ? $argv[2] : &#34;temp/&#34;, isset($argv[3]) ? $argv[3] : &#34;decoded/&#34;);

?&#62;
</pre>
<p>As for the people who really want to protect their code, you might want to have it on zend or ioncube, although they are also engineering reverible, just a bit harder.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/11/17/hacking-eval-and-base64-php-encrypt/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>label for=&#8221;id&#8221; don&#8217;t work on IE</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/09/27/label-forid-dont-work-on-ie?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=label-forid-dont-work-on-ie</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/09/27/label-forid-dont-work-on-ie#comments</comments>
		<pubDate>Mon, 27 Sep 2010 04:20:18 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tips & Hints]]></category>
		<category><![CDATA[cross browser]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[labels]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=494</guid>
		<description><![CDATA[Problem:

&#60;input type='radio' value='x' id='something_1' name='something'&#62;
&#60;label for='something_1'&#62;cool label&#60;/label&#62;

When user clicks on the label radio should be selected, this only happens on firefox.
Solution:

$(&#34;label&#34;).click(function(){
	if ($(this).attr(&#34;for&#34;) != &#34;&#34;)
		$(&#34;#&#34; + $(this).attr(&#34;for&#34;)).click();
});

More info on this issue:
Stackoverflow posting
]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<pre class="brush: xml;">
&#60;input type='radio' value='x' id='something_1' name='something'&#62;
&#60;label for='something_1'&#62;cool label&#60;/label&#62;
</pre>
<p>When user clicks on the label radio should be selected, this only happens on firefox.</p>
<p><strong>Solution:</strong></p>
<pre class="brush: jscript;">
$(&#34;label&#34;).click(function(){
	if ($(this).attr(&#34;for&#34;) != &#34;&#34;)
		$(&#34;#&#34; + $(this).attr(&#34;for&#34;)).click();
});
</pre>
<p><strong>More info on this issue:</strong></p>
<p><a href="http://stackoverflow.com/questions/2677933/clickable-label-not-working-in-ie-8" target="_blank">Stackoverflow posting</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/09/27/label-forid-dont-work-on-ie/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Validator scrollTo snippet</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/09/26/jquery-validator-scrollto-snippet?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=jquery-validator-scrollto-snippet</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/09/26/jquery-validator-scrollto-snippet#comments</comments>
		<pubDate>Mon, 27 Sep 2010 02:01:13 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tips & Hints]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jquery scrollTo]]></category>
		<category><![CDATA[jquery validator]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=491</guid>
		<description><![CDATA[Problem:
How to automatically scroll to the first wrong input on a long form validated using jquery validator?
Solution:

invalidHandler: function(form,validator) {
	if (validator.numberOfInvalids())
		setTimeout(function(){
			$.scrollTo($(&#34;form_id&#34;).(&#34;:input.error:first&#34;), 500);
		},250);
}

]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>How to automatically scroll to the first wrong input on a long form validated using jquery validator?</p>
<p><strong>Solution:</strong></p>
<pre class="brush: jscript;">
invalidHandler: function(form,validator) {
	if (validator.numberOfInvalids())
		setTimeout(function(){
			$.scrollTo($(&#34;form_id&#34;).(&#34;:input.error:first&#34;), 500);
		},250);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/09/26/jquery-validator-scrollto-snippet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Itaú shopline class</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/09/03/itau-shopline-class?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=itau-shopline-class</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/09/03/itau-shopline-class#comments</comments>
		<pubDate>Fri, 03 Sep 2010 04:33:12 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[integração]]></category>
		<category><![CDATA[itaú]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[payment gateway]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=480</guid>
		<description><![CDATA[Problema:
A integração PHP proposta pelo Itaú é desastrosa, uma classe compilada em Java que requer um módulo beta descontinuado em PHP.
Solução:
Utilizando engenharia reversa descompilei a classe:

package Itau;

public class Itaucripto
{

    public Itaucripto()
    {
        CHAVE_ITAU = &#34;SEGUNDA12345ITAU&#34;;
        [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problema:</strong></p>
<p>A integração PHP proposta pelo Itaú é desastrosa, uma classe compilada em Java que requer um módulo beta descontinuado em PHP.</p>
<p><strong>Solução:</strong></p>
<p>Utilizando engenharia reversa descompilei a classe:</p>
<pre class="brush: java;">
package Itau;

public class Itaucripto
{

    public Itaucripto()
    {
        CHAVE_ITAU = &#34;SEGUNDA12345ITAU&#34;;
        TAM_COD_EMP = 26;
        TAM_CHAVE = 16;
        numbers = &#34;0123456789&#34;;
        sbox = new int[256];
        key = new int[256];
        numPed = &#34;&#34;;
        tipPag = &#34;&#34;;
        codEmp = &#34;&#34;;
    }

    private String Algoritmo(String s, String s1)
    {
        int k = 0;
        int l = 0;
        String s2 = &#34;&#34;;
        Inicializa(s1);
        for(int j = 1; j &#60;= s.length(); j++)
        {
            k = (k + 1) % 256;
            l = (l + sbox[k]) % 256;
            int i = sbox[k];
            sbox[k] = sbox[l];
            sbox[l] = i;
            int i1 = sbox[(sbox[k] + sbox[l]) % 256];
            int j1 = s.charAt(j - 1) ^ i1;
            s2 = s2 + (char)j1;
        }

        return s2;
    }

    private String PreencheBranco(String s, int i)
    {
        String s1;
        for(s1 = s.toString(); s1.length() &#60; i; s1 = s1 + &#34; &#34;);
        return s1.substring(0, i);
    }

    private String PreencheZero(String s, int i)
    {
        String s1;
        for(s1 = s.toString(); s1.length() &#60; i; s1 = &#34;0&#34; + s1);
        return s1.substring(0, i);
    }

    private void Inicializa(String s)
    {
        int i1 = s.length();
        for(int j = 0; j &#60;= 255; j++)
        {
            key[j] = s.charAt(j % i1);
            sbox[j] = j;
        }

        int l = 0;
        for(int k = 0; k &#60;= 255; k++)
        {
            l = (l + sbox[k] + key[k]) % 256;
            int i = sbox[k];
            sbox[k] = sbox[l];
            sbox[l] = i;
        }

    }

    private boolean isNumeric(String s)
    {
        if(s.length() &#62; 1)
        {
            boolean flag = true;
            for(int i = 0; i &#60; s.length(); i++)
            {
                flag = isNumeric(s.substring(i, i + 1));
                if(!flag)
                    return flag;
            }

            return flag;
        }
        return numbers.indexOf(s) &#62;= 0;
    }

    private String Converte(String s)
    {
        char c2 = (char)(int)(26D * Math.random() + 65D);
        String s1 = &#34;&#34; + c2;
        for(int i = 0; i &#60; s.length(); i++)
        {
            char c1 = s.charAt(i);
            char c = c1;
            s1 = s1 + Integer.toString(c);
            char c3 = (char)(int)(26D * Math.random() + 65D);
            s1 = s1 + c3;
        }

        return s1;
    }

    private String Desconverte(String s)
    {
        String s1 = &#34;&#34;;
        for(int i = 0; i &#60; s.length(); i++)
        {
            String s2 = &#34;&#34;;
            for(char c = s.charAt(i); Character.isDigit(c); c = s.charAt(i))
            {
                s2 = s2 + s.charAt(i);
                i++;
            }

            if(s2.compareTo(&#34;&#34;) != 0)
            {
                int j = Integer.parseInt(s2);
                s1 = s1 + (char)j;
            }
        }

        return s1;
    }

    public String geraDados(String s, String s1, String s2, String s3, String s4, String s5, String s6,
            String s7, String s8, String s9, String s10, String s11, String s12, String s13,
            String s14, String s15, String s16, String s17)
    {
        s = s.toUpperCase();
        s4 = s4.toUpperCase();
        if(s.length() != TAM_COD_EMP)
            return &#34;Erro: tamanho do codigo da empresa diferente de 26 posi\347\365es.&#34;;
        if(s4.length() != TAM_CHAVE)
            return &#34;Erro: tamanho da chave da chave diferente de 16 posi\347\365es.&#34;;
        if(s1.length() &#60; 1 &#124;&#124; s1.length() &#62; 8)
            return &#34;Erro: n\372mero do pedido inv\341lido.&#34;;
        if(isNumeric(s1))
            s1 = PreencheZero(s1, 8);
        else
            return &#34;Erro: numero do pedido n\343o \351 num\351rico.&#34;;
        if(s2.length() &#60; 1 &#124;&#124; s2.length() &#62; 11)
            return &#34;Erro: valor da compra inv\341lido.&#34;;
        int i = s2.indexOf(',');
        if(i != -1)
        {
            String s20 = s2.substring(i + 1);
            if(!isNumeric(s20))
                return &#34;Erro: valor decimal n\343o \351 num\351rico.&#34;;
            if(s20.length() != 2)
                return &#34;Erro: valor decimal da compra deve possuir 2 posi\347\365es ap\363s a virgula.&#34;;
            s2 = s2.substring(0, s2.length() - 3) + s20;
        } else
        {
            if(!isNumeric(s2))
                return &#34;Erro: valor da compra n\343o \351 num\351rico.&#34;;
            if(s2.length() &#62; 8)
                return &#34;Erro: valor da compra deve possuir no m\341ximo 8 posi\347\365es antes da virgula.&#34;;
            s2 = s2 + &#34;00&#34;;
        }
        s2 = PreencheZero(s2, 10);
        s6 = s6.trim();
        if(s6.compareTo(&#34;02&#34;) != 0 &#38;&#38; s6.compareTo(&#34;01&#34;) != 0 &#38;&#38; s6.compareTo(&#34;&#34;) != 0)
            return &#34;Erro: c\363digo de inscri\347\343o inv\341lido.&#34;;
        if(s7.compareTo(&#34;&#34;) != 0 &#38;&#38; !isNumeric(s7) &#38;&#38; s7.length() &#62; 14)
            return &#34;Erro: n\372mero de inscri\347\343o inv\341lido.&#34;;
        if(s10.compareTo(&#34;&#34;) != 0 &#38;&#38; (!isNumeric(s10) &#124;&#124; s10.length() != 8))
            return &#34;Erro: cep inv\341lido.&#34;;
        if(s13.compareTo(&#34;&#34;) != 0 &#38;&#38; (!isNumeric(s13) &#124;&#124; s13.length() != 8))
            return &#34;Erro: data de vencimento inv\341lida.&#34;;
        if(s15.length() &#62; 60)
            return &#34;Erro: observa\347\343o adicional 1 inv\341lida.&#34;;
        if(s16.length() &#62; 60)
            return &#34;Erro: observa\347\343o adicional 2 inv\341lida.&#34;;
        if(s17.length() &#62; 60)
        {
            return &#34;Erro: observa\347\343o adicional 3 inv\341lida.&#34;;
        } else
        {
            s3 = PreencheBranco(s3, 40);
            s5 = PreencheBranco(s5, 30);
            s6 = PreencheBranco(s6, 2);
            s7 = PreencheBranco(s7, 14);
            s8 = PreencheBranco(s8, 40);
            s9 = PreencheBranco(s9, 15);
            s10 = PreencheBranco(s10, 8);
            s11 = PreencheBranco(s11, 15);
            s12 = PreencheBranco(s12, 2);
            s13 = PreencheBranco(s13, 8);
            s14 = PreencheBranco(s14, 60);
            s15 = PreencheBranco(s15, 60);
            s16 = PreencheBranco(s16, 60);
            s17 = PreencheBranco(s17, 60);
            String s18 = Algoritmo(s1 + s2 + s3 + s5 + s6 + s7 + s8 + s9 + s10 + s11 + s12 + s13 + s14 + s15 + s16 + s17, s4);
            String s19 = Algoritmo(s + s18, CHAVE_ITAU);
            return Converte(s19);
        }
    }

    public String geraCripto(String s, String s1, String s2)
    {
        if(s.length() != TAM_COD_EMP)
            return &#34;Erro: tamanho do codigo da empresa diferente de 26 posi\347\365es.&#34;;
        if(s2.length() != TAM_CHAVE)
            return &#34;Erro: tamanho da chave da chave diferente de 16 posi\347\365es.&#34;;
        s1 = s1.trim();
        if(s1.compareTo(&#34;&#34;) == 0)
        {
            return &#34;Erro: c\363digo do sacado inv\341lido.&#34;;
        } else
        {
            String s3 = Algoritmo(s1, s2);
            String s4 = Algoritmo(s + s3, CHAVE_ITAU);
            return Converte(s4);
        }
    }

    public String geraConsulta(String s, String s1, String s2, String s3)
    {
        if(s.length() != TAM_COD_EMP)
            return &#34;Erro: tamanho do codigo da empresa diferente de 26 posi\347\365es.&#34;;
        if(s3.length() != TAM_CHAVE)
            return &#34;Erro: tamanho da chave da chave diferente de 16 posi\347\365es.&#34;;
        if(s1.length() &#60; 1 &#124;&#124; s1.length() &#62; 8)
            return &#34;Erro: n\372mero do pedido inv\341lido.&#34;;
        if(isNumeric(s1))
            s1 = PreencheZero(s1, 8);
        else
            return &#34;Erro: numero do pedido n\343o \351 num\351rico.&#34;;
        if(s2.compareTo(&#34;0&#34;) != 0 &#38;&#38; s2.compareTo(&#34;1&#34;) != 0)
        {
            return &#34;Erro: formato inv\341lido.&#34;;
        } else
        {
            String s4 = Algoritmo(s1 + s2, s3);
            String s5 = Algoritmo(s + s4, CHAVE_ITAU);
            return Converte(s5);
        }
    }

    public String decripto(String s, String s1)
    {
        s = Desconverte(s);
        String s2 = Algoritmo(s, s1);
        codEmp = s2.substring(0, 26);
        numPed = s2.substring(26, 34);
        tipPag = s2.substring(34, 36);
        return s2;
    }

    public String retornaCodEmp()
    {
        return codEmp;
    }

    public String retornaPedido()
    {
        return numPed;
    }

    public String retornaTipPag()
    {
        return tipPag;
    }

    public String geraDadosGenerico(String s, String s1, String s2)
    {
        s = s.toUpperCase();
        s2 = s2.toUpperCase();
        if(s.length() != TAM_COD_EMP)
            return &#34;Erro: tamanho do codigo da empresa diferente de 26 posi\347\365es.&#34;;
        if(s2.length() != TAM_CHAVE)
            return &#34;Erro: tamanho da chave da chave diferente de 16 posi\347\365es.&#34;;
        if(s1.length() &#60; 1)
        {
            return &#34;Erro: sem dados.&#34;;
        } else
        {
            String s3 = Algoritmo(s1, s2);
            String s4 = Algoritmo(s + s3, CHAVE_ITAU);
            return Converte(s4);
        }
    }

    private int sbox[];
    private int key[];
    private String codEmp;
    private String numPed;
    private String tipPag;
    private String CHAVE_ITAU;
    private int TAM_COD_EMP;
    private int TAM_CHAVE;
    private String dados;
    public String numbers;
}
</pre>
<p>Nada satisfatório, mas é melhor do que utilizar o módulo java beta ou a integração windows emulada no linux.</p>
<p>Também achei um <a href="http://caioariede.com/2008/integracao-itau-shopline-php" target="_blank">port em PHP</a>, não é uma maravilha, mas dá pro gasto por enquanto.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/09/03/itau-shopline-class/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>preg (regular expression) to get emails in php</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/08/28/preg-regular-expression-to-get-emails-in-php?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=preg-regular-expression-to-get-emails-in-php</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/08/28/preg-regular-expression-to-get-emails-in-php#comments</comments>
		<pubDate>Sat, 28 Aug 2010 12:10:19 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[preg]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=478</guid>
		<description><![CDATA[Problem:
A regular experssion pattern for getting emails on a random string.
Solution:

preg_match_all(
	&#34;/[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i&#34;,
	$string,
	$matches,
	PREG_PATTERN_ORDER
);

]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>A regular experssion pattern for getting emails on a random string.</p>
<p><strong>Solution:</strong></p>
<pre class="brush: php;">
preg_match_all(
	&#34;/[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i&#34;,
	$string,
	$matches,
	PREG_PATTERN_ORDER
);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/08/28/preg-regular-expression-to-get-emails-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

