<?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>zsygab.com &#187; php</title>
	<atom:link href="http://www.zsygab.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zsygab.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 10 Jan 2012 13:37:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>PHP fix length random string</title>
		<link>http://www.zsygab.com/php-fix-length-random-string/</link>
		<comments>http://www.zsygab.com/php-fix-length-random-string/#comments</comments>
		<pubDate>Mon, 30 May 2011 08:50:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming - Computers]]></category>
		<category><![CDATA[characters]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rand]]></category>
		<category><![CDATA[randoms]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.zsygab.com/?p=271</guid>
		<description><![CDATA[If you need a simple function to generate a fixed length string with random characters, use this: function genRandomString($length) { $characters = &#8217;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ&#8217;; $string = &#8221;; for ($p = 0; $p &#60; $length; $p++) $string .= $characters[mt_rand(0, strlen($characters)-1)]; return $string; }]]></description>
			<content:encoded><![CDATA[<p>If you need a simple function to generate a fixed length string with random characters, use this:</p>
<blockquote><p>function genRandomString($length) {<br />
$characters = &#8217;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ&#8217;;<br />
$string = &#8221;;<br />
for ($p = 0; $p &lt; $length; $p++)<br />
$string .= $characters[mt_rand(0, strlen($characters)-1)];<br />
return $string;<br />
}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.zsygab.com/php-fix-length-random-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send special characters with PHP from Ajax calls</title>
		<link>http://www.zsygab.com/send-special-characters-with-php-from-ajax-calls/</link>
		<comments>http://www.zsygab.com/send-special-characters-with-php-from-ajax-calls/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 19:07:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming - Computers]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[calls]]></category>
		<category><![CDATA[characters]]></category>
		<category><![CDATA[htmlentities]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rawurlencode]]></category>
		<category><![CDATA[special]]></category>

		<guid isPermaLink="false">http://www.zsygab.com/?p=48</guid>
		<description><![CDATA[Yesterday I had a very strange situation… Using a jQuery datatable, I was trying to display some info, populating the table with Ajax calls… Everything was OK, until somebody didn’t try to use special characters, like “ö” or ENTER… Than the datatable went crazy… Here is what I found out: Basically, with Ajax I was [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I had a very strange situation… Using a jQuery datatable, I was trying to display some info, populating the table with Ajax calls… Everything was OK, until somebody didn’t try to use special characters, like “ö” or ENTER… Than the datatable went crazy… Here is what I found out:</p>
<p>Basically, with Ajax I was calling a php file, which will return the result of a query, let’s say it’s somebody’s name now. If that name contains special characters, first you have to call the following function in the php file:</p>
<blockquote><p>function fix_str($str){<br />
$str = htmlentities($str, ENT_COMPAT, ‘UTF-8′);<br />
$str = str_replace(chr(10),”,$str);<br />
$str = str_replace(chr(13),’<br />
’,$str);<br />
$str = rawurlencode($str);<br />
return $str;<br />
}</p></blockquote>
<p>This guarantees that the result sent back to the jQuery won’t be messed up…</p>
<p>On the Javascript side, to get the result well formatted, if you have the Ajax call result in the variable “resp”:</p>
<blockquote><p>str = unescape(resp);</p></blockquote>
<p>This way you will be able to pass any character through the Ajax call.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zsygab.com/send-special-characters-with-php-from-ajax-calls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check all uncheck all HTML checkboxes with Javascript</title>
		<link>http://www.zsygab.com/check-all-uncheck-all-html-checkboxes-with-javascript/</link>
		<comments>http://www.zsygab.com/check-all-uncheck-all-html-checkboxes-with-javascript/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 18:55:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming - Computers]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[uncheck]]></category>

		<guid isPermaLink="false">http://www.zsygab.com/?p=40</guid>
		<description><![CDATA[The following little piece of code shows how to check all / uncheck all HTML checkboxes with simple Javascript, without jQuery. It’s not something hard to do, but as I use it a lot, it’s nice to have it at one click… &#60;form name=”formname” method=”POST” action=”?action=dosomething”&#62; Check all: &#60;input type=”checkbox” name=”checkall” id=”checkall” value=”Check All” onclick=”Check(‘formname’,$(‘.check_list’))”&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>The following little piece of code shows how to check all / uncheck all HTML checkboxes with simple Javascript, without jQuery. It’s not something hard to do, but as I use it a lot, it’s nice to have it at one click…</p>
<blockquote><p>&lt;form name=”formname” method=”POST” action=”?action=dosomething”&gt;</p>
<p>Check all: &lt;input type=”checkbox” name=”checkall” id=”checkall” value=”Check All” onclick=”Check(‘formname’,$(‘.check_list’))”&gt;</p>
<p>Option 1&lt;input type=’checkbox’ class=”check_list” name=”check_list[]” value=”1″&gt;<br />
Option 2&lt;input type=’checkbox’ class=”check_list” name=”check_list[]” value=”2″&gt;<br />
Option 3&lt;input type=’checkbox’ class=”check_list” name=”check_list[]” value=”3″&gt;</p>
<p>&lt;/form&gt;</p></blockquote>
<p>The corresponding Javascript code:</p>
<blockquote><p>function Check(form_name,chk){ // alternate check all/check none of items</p>
<p>if(eval(“document.”+form_name+”.checkall.value”)==”Check All”){<br />
for (i = 0; i &lt; chk.length; i++)<br />
chk[i].checked = true ;<br />
eval(“document.”+form_name+”.checkall.value=’UnCheck All’”);<br />
}</p>
<p>else{<br />
for (i = 0; i &lt; chk.length; i++)<br />
chk[i].checked = false ;<br />
eval(“document.”+form_name+”.checkall.value=’Check All’”);<br />
}</p>
<p>}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.zsygab.com/check-all-uncheck-all-html-checkboxes-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sort multi-dimensional array in PHP</title>
		<link>http://www.zsygab.com/sort-multi-dimensional-array-in-php/</link>
		<comments>http://www.zsygab.com/sort-multi-dimensional-array-in-php/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 18:48:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming - Computers]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[dimensions]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[multi-dimensions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[usort]]></category>

		<guid isPermaLink="false">http://www.zsygab.com/?p=37</guid>
		<description><![CDATA[How to sort multi-dimensional arrays using PHP? Sorting one dimensional array is pretty easy, but to do this with two or multi-dimensional arrays, is a little different. Here is how to do it: There’s a given 2 dimensional array: $array[] = array(“id”=&#62;1,”title”=&#62;”Monkey”); $array[] = array(“id”=&#62;2,”title”=&#62;”Alien”); $array[] = array(“id”=&#62;3,”title”=&#62;”Stargate”); $array[] = array(“id”=&#62;4,”title”=&#62;”New”); We use the usort [...]]]></description>
			<content:encoded><![CDATA[<p>How to sort multi-dimensional arrays using PHP? Sorting one dimensional array is pretty easy, but to do this with two or multi-dimensional arrays, is a little different. Here is how to do it:</p>
<p>There’s a given 2 dimensional array:</p>
<blockquote><p>$array[] = array(“id”=&gt;1,”title”=&gt;”Monkey”);<br />
$array[] = array(“id”=&gt;2,”title”=&gt;”Alien”);<br />
$array[] = array(“id”=&gt;3,”title”=&gt;”Stargate”);<br />
$array[] = array(“id”=&gt;4,”title”=&gt;”New”);</p></blockquote>
<p>We use the usort function of PHP:</p>
<blockquote><p>usort($array, “cmp”);</p></blockquote>
<p>… where cmp is the following function:</p>
<blockquote><p>function cmp($a, $b){<br />
return strcmp($a["title"], $b["title"]);<br />
}</p></blockquote>
<p>After sorting the $a array, it will look like this:</p>
<blockquote><p>$array[0] = array(“id”=&gt;2,”title”=&gt;”Alien”);<br />
$array[1] = array(“id”=&gt;1,”title”=&gt;”Monkey”);<br />
$array[2] = array(“id”=&gt;4,”title”=&gt;”New”);<br />
$array[3] = array(“id”=&gt;3,”title”=&gt;”Stargate”);</p></blockquote>
<p>Now, the array is sorted by ‘title’ in ascending order. To sort in in descending order, just change the order of the compared elements in the cmp function:</p>
<blockquote><p>return strcmp($b["title"], $a["title"]);</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.zsygab.com/sort-multi-dimensional-array-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Excel file from PHP with tables using headers</title>
		<link>http://www.zsygab.com/create-excel-file-from-php-with-tables-using-headers/</link>
		<comments>http://www.zsygab.com/create-excel-file-from-php-with-tables-using-headers/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 18:40:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming - Computers]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[spreadsheet]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://www.zsygab.com/?p=31</guid>
		<description><![CDATA[Did You ever needed to create pure and simple Excel spreadsheets from php? Are you tired with complicated classes, large and nonsense code? Here is a tiny code sample, showing how easy it  is to create Excel files directly from a php file. I won’t comment the lines, as the code is obvious… $file_name = [...]]]></description>
			<content:encoded><![CDATA[<p>Did You ever needed to create pure and simple Excel spreadsheets from php? Are you tired with complicated classes, large and nonsense code? Here is a tiny code sample, showing how easy it  is to create Excel files directly from a php file. I won’t comment the lines, as the code is obvious…</p>
<blockquote><p>$file_name = “myfile.xls”;</p>
<p>header(‘Pragma: public’);<br />
header(‘Expires: 0′);<br />
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0′);<br />
header(‘Cache-Control: public’);<br />
header(‘Content-Description: File Transfer’);<br />
header(‘Content-Type: text/xls; name=”‘ . $file_name . ‘”‘);<br />
header(‘Content-Disposition: attachment; filename=”‘ . $file_name . ‘”‘);<br />
header(‘Content-Transfer-Encoding: binary’);</p>
<p>$content = ‘&lt;table&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;Header1 (A)&lt;/td&gt;<br />
&lt;td&gt;Header2 (B)&lt;/td&gt;<br />
&lt;td&gt;Header3 (C)&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;Content 1A&lt;/td&gt;<br />
&lt;td&gt;Content 1B&lt;/td&gt;<br />
&lt;td&gt;Content 1C&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;Content 2A&lt;/td&gt;<br />
&lt;td&gt;&amp;nbsp;&lt;/td&gt;<br />
&lt;td&gt;Content 2C&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;’;</p>
<p>echo $content</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.zsygab.com/create-excel-file-from-php-with-tables-using-headers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connect to strato.de with imap PHP functions</title>
		<link>http://www.zsygab.com/connect-to-strato-de-with-imap-php-functions/</link>
		<comments>http://www.zsygab.com/connect-to-strato-de-with-imap-php-functions/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 18:33:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming - Computers]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[strato.de]]></category>

		<guid isPermaLink="false">http://www.zsygab.com/?p=26</guid>
		<description><![CDATA[Connecting to strato.de with imap isn’t easy at all, as there’s little documentations on the Internet, and they are mainly in dutch. So I will present in the following lines how you can access your e-mails from a php file. $server = ‘{imap.strato.de:143}’; $connection = imap_open($server, “youremail@yourdomain.nl”, “yourpassword”); print_r(imap_errors()); $mailboxes = imap_list($connection, $server, ‘*’); foreach($mailboxes [...]]]></description>
			<content:encoded><![CDATA[<p>Connecting to strato.de with imap isn’t easy at all, as there’s little documentations on the Internet, and they are mainly in dutch. So I will present in the following lines how you can access your e-mails from a php file.</p>
<blockquote><p>$server = ‘{imap.strato.de:143}’;<br />
$connection = imap_open($server, “youremail@yourdomain.nl”, “yourpassword”);</p>
<p>print_r(imap_errors());</p>
<p>$mailboxes = imap_list($connection, $server, ‘*’);</p>
<p>foreach($mailboxes as $mailbox)<br />
$shortname = str_replace($server, ”, $mailbox);</p>
<p>imap_reopen($connection, $server.’INBOX’);</p>
<p>$count = imap_num_msg($connection);</p>
<p>for($i = 1; $i &lt;= $count; $i++) {<br />
$header = imap_headerinfo($connection, $i);<br />
$raw_body = imap_body($connection, $i);<br />
}</p></blockquote>
<p>$server – the connection parameteres, differs from server to server. For exemple:</p>
<ul>
<li>Google: {imap.gmail.com:993/ssl/novalidate-cert}</li>
</ul>
<ul>
<li>Google Apps: {imap.googlemail.com:993/ssl/novalidate-cert}</li>
</ul>
<p>$connection: this is the IMAP stream</p>
<p>$mailboxes: will contain all the mailboxes you have (Inbox, Trash, Sent + persobal mailboxes)</p>
<p>$shortname: will contain just the name of the mailboxes, without their server address</p>
<p>imap-reopen: you can make a new stream, connecting to a given mailbox (INBOX in my case)</p>
<p>$count: how many mails do you have in the selected mailbox</p>
<p>- the last for cycle runs through the mailbox, and for every e-mail gets it’s header information ($header) and the mail’s content ($raw_body)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zsygab.com/connect-to-strato-de-with-imap-php-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copy / duplicate database with PHP</title>
		<link>http://www.zsygab.com/copy-duplicate-database-with-php/</link>
		<comments>http://www.zsygab.com/copy-duplicate-database-with-php/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 12:04:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming - Computers]]></category>
		<category><![CDATA[clone]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[data tables]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://www.zsygab.com/?p=6</guid>
		<description><![CDATA[How to copy / clone / duplicate an entire database, with all the tables and data contained? Here are some definitions for start&#8230;: define(&#8220;DB_HOST&#8221;, &#8220;localhost&#8221;); define(&#8220;DB_DATABASE&#8221;, &#8220;is_general&#8221;); define(&#8220;DB_DATABASE_NEW&#8221;, &#8220;is_general&#8221;); define(&#8220;DB_USERNAME&#8221;, &#8220;general&#8221;); define(&#8220;DB_PASSWORD&#8221;, &#8220;g3n3r@l&#8221;); Connect to the original database: mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD); mysql_select_db(DB_DATABASE); Create the new database and add an existing user to it (in our [...]]]></description>
			<content:encoded><![CDATA[<p>How to copy / clone / duplicate an entire database, with all the tables and data contained?</p>
<p>Here are some definitions for start&#8230;:</p>
<blockquote><p>define(&#8220;DB_HOST&#8221;, &#8220;localhost&#8221;);<br />
define(&#8220;DB_DATABASE&#8221;, &#8220;is_general&#8221;);<br />
define(&#8220;DB_DATABASE_NEW&#8221;, &#8220;is_general&#8221;);<br />
define(&#8220;DB_USERNAME&#8221;, &#8220;general&#8221;);<br />
define(&#8220;DB_PASSWORD&#8221;, &#8220;g3n3r@l&#8221;);</p></blockquote>
<p>Connect to the original database:</p>
<blockquote><p>mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD);<br />
mysql_select_db(DB_DATABASE);</p></blockquote>
<p>Create the new database and add an existing user to it (in our case, general) with all privileges:</p>
<blockquote><p>mysql_query(&#8220;CREATE DATABASE &#8220;.DB_DATABASE_NEW);<br />
mysql_query(&#8220;GRANT ALL PRIVILEGES ON &#8220;.DB_DATABASE_NEW.&#8221;.* TO &#8216;general&#8217;@'%&#8217; WITH GRANT OPTION&#8221;);</p></blockquote>
<p>Get all the table names from the original table (here you must be careful, because if there are dependecies, as foreign keys from one table the another, it can cause some problems, as the order of the tables is important when they will be recreated):</p>
<blockquote><p>$r = mysql_query(&#8220;SELECT Table_name,Table_rows FROM information_schema.tables WHERE TABLE_SCHEMA = &#8216;is_default&#8217;&#8221;);<br />
while ($d= mysql_fetch_assoc($r))<br />
$tables[] = $d['Table_name'];</p></blockquote>
<p>If the database is not empty, so it contains tables:</p>
<blockquote><p>if (is_array($tables))<br />
foreach ($tables as $v){</p></blockquote>
<p>Connect to the new database and create the tables with their structure:</p>
<blockquote><p>$r = mysql_query(&#8220;SHOW CREATE TABLE `&#8221;.$v.&#8221;`&#8221;);<br />
$d= mysql_fetch_assoc($r);<br />
mysql_select_db(DB_DATABASE_NEW);<br />
mysql_query($d['Create Table']);</p></blockquote>
<p>Copy the data from original table:</p>
<blockquote><p>$data = &#8221;;<br />
mysql_select_db(DB_DATABASE);<br />
$r = mysql_query(&#8220;SELECT * FROM `&#8221;.$v.&#8221;`&#8221;);<br />
while ($d= mysql_fetch_assoc($r))<br />
$data[] = $d;</p></blockquote>
<p>Paste the data into the corresponding table in the new database:</p>
<blockquote><p>mysql_select_db(DB_DATABASE_NEW);<br />
if (is_array($data))<br />
foreach ($data as $d)<br />
// and here you will insert the data &#8220;$d&#8221; into the table &#8220;$v&#8221;, as this is not truly related to this post, and you should learn from yourself too&#8230; <img src='http://www.zsygab.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.zsygab.com/copy-duplicate-database-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

