<?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>Maribol Labs &#187; PHP</title>
	<atom:link href="http://www.mlabs.info/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mlabs.info</link>
	<description>Programming and Design Blog</description>
	<lastBuildDate>Mon, 28 Nov 2011 07:41:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Using AJAX and PHP together</title>
		<link>http://www.mlabs.info/ajax-php/</link>
		<comments>http://www.mlabs.info/ajax-php/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 18:21:58 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=922</guid>
		<description><![CDATA[In this tutorial i&#8217;ll show you how to use PHP and AJAX together and get the results that you need. Here&#8217;s an example of a function that executes a ajax request View Code JAVASCRIPTfunction execAjax&#40;type&#41;&#123; $.ajax&#40;&#123; url: 'ajax.php?type='+type, dataType: 'json', success: function&#40; data &#41; &#123; var items = &#91;&#93;; &#160; $.each&#40;data, function&#40;key, val&#41; &#123; items.push&#40;'&#60;li [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial i&#8217;ll show you how to use PHP and AJAX together and get the results that you need.</p>
<p><b>Here&#8217;s an example of a function that executes a ajax request</b></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code6'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9226"><td class="code" id="p922code6"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> execAjax<span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ajax.php?type='</span><span style="color: #339933;">+</span>type<span style="color: #339933;">,</span>
      dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
      success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> data <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003366; font-weight: bold;">var</span> items <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
         $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            items.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;li id=&quot;'</span> <span style="color: #339933;">+</span> key <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> val <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#results'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;ul/&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #3366CC;">'class'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'results-list'</span><span style="color: #339933;">,</span>
               html<span style="color: #339933;">:</span> items.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This function should add a list with all the items resulted from the request.</p>
<p><b>Example of use:</b></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code7'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9227"><td class="code" id="p922code7"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;javascript:;&quot; onclick=&quot;execAjax('fruits')&quot;&gt;fruits&lt;/a&gt;
&lt;a href=&quot;javascript:;&quot; onclick=&quot;execAjax('vegetables')&quot;&gt;vegetables&lt;/a&gt;
&lt;a href=&quot;javascript:;&quot; onclick=&quot;execAjax('furniture')&quot;&gt;furniture&lt;/a&gt;
&nbsp;
&lt;div id=&quot;results&quot;&gt;&lt;/div&gt;</pre></td></tr></table></div>

<p>And the ajax.php return an array encoded in json.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9228"><td class="code" id="p922code8"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'fruits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'bannana'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'orange'</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'vegetables'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'potato'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'carrot'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'onion'</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'furniture'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'chair'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'desk'</span>
   <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$type</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If we&#8217;ve clicked on the &#8220;fruits&#8221; link, will get a result like:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code9'); return false;">View Code</a> JSON</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9229"><td class="code" id="p922code9"><pre class="json" style="font-family:monospace;">[&quot;apple&quot;,&quot;bannana&quot;,&quot;orange&quot;]</pre></td></tr></table></div>

<p>This encoded array will be transformed in list with the &#8220;each&#8221; function from jquery and the result that you should see is:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code10'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92210"><td class="code" id="p922code10"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;results&quot;&gt;
   &lt;ul class=&quot;results-list&quot;&gt;
      &lt;li id=&quot;0&quot;&gt;apple&lt;/li&gt;
      &lt;li id=&quot;1&quot;&gt;bannana&lt;/li&gt;
      &lt;li id=&quot;2&quot;&gt;orange&lt;/li&gt;
   &lt;/ul&gt;
&lt;/div&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/ajax-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security Tutorial #2: Are you protected against sql injections?</title>
		<link>http://www.mlabs.info/security-tutorial-2-protected-sql-injections/</link>
		<comments>http://www.mlabs.info/security-tutorial-2-protected-sql-injections/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 12:34:42 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[anti sql injection]]></category>
		<category><![CDATA[mysql_real_escape_string]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[stripslashes]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=965</guid>
		<description><![CDATA[There are alot of websites that are vulnerable to sql injections. In this tutorial i&#8217;ll give you some examples with methods to protect you website. &#160; Make your id from url (int) Let&#8217;s assume that you get the id like this: View Code PHP $id = $_GET&#91;'id'&#93;; Well with this, your site may be vulnerable. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mlabs.info/wp-content/uploads/2011/07/Security-Centre.png"><img src="http://www.mlabs.info/wp-content/uploads/2011/07/Security-Centre.png" alt="" title="Security Centre" width="128" height="128" class="alignleft size-full wp-image-957" /></a>There are alot of websites that are vulnerable to sql injections.<br />
In this tutorial i&#8217;ll give you some examples with methods to protect you website.</p>
<div style="clear:both;"></div>
<p>&nbsp;</p>
<p><strong>Make your id from url <em>(int) </em></strong></p>
<p>Let&#8217;s assume that you get the id like this:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code15'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p96515"><td class="code" id="p965code15"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Well with this, your site may be vulnerable.</p>
<p>But if you use like this it will never be vulerable from this variable:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p96516"><td class="code" id="p965code16"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Basically this will make your id an id, i mean the value returned is always numeric.</p>
<p>&nbsp;</p>
<p><strong>Use the <em>mysql_real_escape_string</em> function</strong><br />
This function may help you alot!</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code17'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p96517"><td class="code" id="p965code17"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$city</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'city'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT firstname, lastname FROM people WHERE city=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$city</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Note:</strong> if <em>magic_quotes_gpc</em> is enabled you should use:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code18'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p96518"><td class="code" id="p965code18"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$city</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'city'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT firstname, lastname FROM people WHERE city=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$city</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/security-tutorial-2-protected-sql-injections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security Tutorial #1: Password hashing</title>
		<link>http://www.mlabs.info/security-tutorial-1-password-hashing/</link>
		<comments>http://www.mlabs.info/security-tutorial-1-password-hashing/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 15:10:23 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[salt]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=953</guid>
		<description><![CDATA[In the past two years i&#8217;ve used many methods to hash a password. The best method i used is by adding a salt and then encrypting with md5. If you encrypt a password without a salt is more easily (but almost impossible) to find the password. It&#8217;s important to know that if you want to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mlabs.info/wp-content/uploads/2011/07/Security-Centre.png"><img src="http://www.mlabs.info/wp-content/uploads/2011/07/Security-Centre.png" alt="" title="Security Centre" width="128" style="border:none;" height="128" class="alignleft size-full wp-image-957" /></a>
<p>In the past two years i&#8217;ve used many methods to hash a password. The best method i used is by adding a salt and then encrypting with md5.</p>
<p>If you encrypt a password without a salt is more easily <em>(but almost impossible)</em> to find the password.</p>
<p>It&#8217;s important to know that if you want to make a login system you have to chose a salt and never change it.</p>
<p>An example how to encrypt:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p953code20'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p95320"><td class="code" id="p953code20"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$salt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'!@#$%^&amp;*()_+'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">.</span><span style="color: #000088;">$salt</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>This code should result and md5 string like:<br />
<b>bbadaec5c53ce3065d14cbe938640088</b></p>
<p><strong>This is the first tutorial in a series of tutorials dedicated to your site security</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/security-tutorial-1-password-hashing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transform image to Base64</title>
		<link>http://www.mlabs.info/transform-image-base64/</link>
		<comments>http://www.mlabs.info/transform-image-base64/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 18:36:57 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[image in email]]></category>
		<category><![CDATA[image to base64]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=914</guid>
		<description><![CDATA[Lately i&#8217;ve seen very often in email newsletters images embed with base64. If you send email newsletters containing image, this is the best way to send. First we try to open the file. View Code PHP $file_path = 'my-image.jpg'; if&#40;$fp = fopen&#40;$file,&#34;rb&#34;, 0&#41;&#41;&#123; &#125;else&#123; echo 'Can\'t open file'; &#125; If the file exist and we [...]]]></description>
			<content:encoded><![CDATA[<p>Lately i&#8217;ve seen very often in email newsletters images embed with base64.<br />
If you send email newsletters containing image, this is the best way to send.</p>
<p>First we try to open the file.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p914code25'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91425"><td class="code" id="p914code25"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$file_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my-image.jpg'</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;rb&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Can\'t open file'</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If the file exist and we have all the rights we need to open it, we read the binary data.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p914code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91426"><td class="code" id="p914code26"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$picture</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>After we have the binary data of the image wi&#8217;ll encode it to base64 and then break it into chunks according to RFC 2045 semantics and we display the html code in a textarea.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p914code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91427"><td class="code" id="p914code27"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$base64</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chunk_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$picture</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$tag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;textarea style=&quot;width:400px;height:300px;&quot;&gt;&lt;img src=&quot;data:image/jpg;base64,'</span><span style="color: #339933;">.</span><span style="color: #000088;">$base64</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;  /&gt;&lt;/textarea&gt;'</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tag</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>..and the final code:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p914code28'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91428"><td class="code" id="p914code28"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$file_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my-image.jpg'</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;rb&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$picture</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$base64</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chunk_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$picture</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$tag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;textarea style=&quot;width:400px;height:300px;&quot;&gt;&lt;img src=&quot;data:image/jpg;base64,'</span><span style="color: #339933;">.</span><span style="color: #000088;">$base64</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;  /&gt;&lt;/textarea&gt;'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tag</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Can\'t open file'</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/transform-image-base64/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to make a search engine on your site. The good method.</title>
		<link>http://www.mlabs.info/search-engine-site-good-method/</link>
		<comments>http://www.mlabs.info/search-engine-site-good-method/#comments</comments>
		<pubDate>Tue, 31 May 2011 18:35:58 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[search engine]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=890</guid>
		<description><![CDATA[Okay, so many people think that if you make a search engine on your site with query like the one below, it&#8217;s okay. View Code SQLSELECT id,name,post FROM posts WHERE name LIKE '%my key%' But it&#8217;s not! Because: Let&#8217;s assume that you have a post called: My little post name If you make a search [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so many people think that if you make a search engine on your site with query like the one below, it&#8217;s okay.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code37'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89037"><td class="code" id="p890code37"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">,</span>post <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%my key%'</span></pre></td></tr></table></div>

<p><b>But it&#8217;s not!</b> </p>
<p>Because:<br />
Let&#8217;s assume that you have a post called: <em>My little post name</em></p>
<p>If you make a search in your database like:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code38'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89038"><td class="code" id="p890code38"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">,</span>post <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%little post%'</span></pre></td></tr></table></div>

<p>you will get a result.</p>
<p>But if you make a search in your database like:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code39'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89039"><td class="code" id="p890code39"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">,</span>post <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%my post%'</span></pre></td></tr></table></div>

<p>you will not get any result.</p>
<p>Okay so the method i use is like this:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code40'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89040"><td class="code" id="p890code40"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">,</span>post <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#40;</span>name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%my%'</span> <span style="color: #993333; font-weight: bold;">AND</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%post%'</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>and this query will get a result.</p>
<p><b>How to do:</b></p>
<p>First we split the string by space with the explode() function and the result is an array with two items.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code41'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89041"><td class="code" id="p890code41"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my post'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>After that, we use the implode() function to create the condition</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code42'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89042"><td class="code" id="p890code42"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$addToQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$addToQuery</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' AND name LIKE &quot;%'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$addToQuery</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The above code should result something like:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code43'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89043"><td class="code" id="p890code43"><pre class="sql" style="font-family:monospace;"> <span style="color: #993333; font-weight: bold;">AND</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">&quot;%my%&quot;</span> <span style="color: #993333; font-weight: bold;">AND</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">&quot;%post%&quot;</span></pre></td></tr></table></div>

<p>Now we have to add this string to SQL Query:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code44'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89044"><td class="code" id="p890code44"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT id,name,post FROM posts WHERE 1 '</span><span style="color: #339933;">.</span><span style="color: #000088;">$addToQuery</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' ORDER BY id DESC'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/search-engine-site-good-method/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to increase memory limit</title>
		<link>http://www.mlabs.info/increase-memory-limit/</link>
		<comments>http://www.mlabs.info/increase-memory-limit/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 16:25:20 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ini_set]]></category>
		<category><![CDATA[memory limit]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=868</guid>
		<description><![CDATA[Recently i needed to increase memory limit for executing a PHP script. And i think there are many of you who don&#8217;t know how to do it. Here is a simple an example: View Code PHPini_set&#40;'memory_limit', '128M'&#41;;]]></description>
			<content:encoded><![CDATA[<p>Recently i needed to increase memory limit for executing a PHP script.<br />
And i think there are many of you who don&#8217;t know how to do it.</p>
<p>Here is a simple an example:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p868code46'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86846"><td class="code" id="p868code46"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'memory_limit'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'128M'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/increase-memory-limit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to transform arrays to objects and object to arrays</title>
		<link>http://www.mlabs.info/transform-arrays-objects-object-arrays/</link>
		<comments>http://www.mlabs.info/transform-arrays-objects-object-arrays/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 08:00:35 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array to object]]></category>
		<category><![CDATA[object to array]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=862</guid>
		<description><![CDATA[I haven&#8217;t wrote any tutorial since two months (i&#8217;ve been very busy lately). Anyway, now i&#8217;ll show you a simple way to transform arrays to objects and objects to arrays. Let&#8217;s start with transformation from arrays to objects. View Code PHP function ArrayToObject&#40;$array&#41;&#123; foreach&#40;$array as $key=&#62;$value&#41;&#123; if&#40;is_array&#40;$value&#41;&#41;&#123; $new_object-&#62;$key = ArrayToObject&#40;$value&#41;; &#125;else&#123; $new_object-&#62;$key = $value; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t wrote any tutorial since two months <em>(i&#8217;ve been very busy lately)</em>.</p>
<p>Anyway, now i&#8217;ll show you a simple way to transform arrays to objects and objects to arrays.</p>
<p>Let&#8217;s start with transformation from arrays to objects.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p862code53'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86253"><td class="code" id="p862code53"><pre class="php" style="font-family:monospace;">   <span style="color: #000000; font-weight: bold;">function</span> ArrayToObject<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$new_object</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> ArrayToObject<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$new_object</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$new_object</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><b>Function explained:</b></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p862code54'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86254"><td class="code" id="p862code54"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Using the <b>foreach</b> function we create a loop with $key and $value for each array item that we get from the function parram <em>$array</em>.</p>
<p>Now that we are in the loop we have to check if the item value is array so that we can pass it again to <b>ArrayToObject()</b> function.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p862code55'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86255"><td class="code" id="p862code55"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>If this function returns true, we call the <b>ArrayToObject()</b> and we start over again but with other value.<br />
If returns false, we create a variable in the new object.</p>
<p>After all the loops are executed we return the object with:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p862code56'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86256"><td class="code" id="p862code56"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">return</span> <span style="color: #000088;">$new_object</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><b>How to use it:</b></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p862code57'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86257"><td class="code" id="p862code57"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dsa'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$object</span> <span style="color: #339933;">=</span> ArrayToObject<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The function for transforming objects to array is:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p862code58'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86258"><td class="code" id="p862code58"><pre class="php" style="font-family:monospace;">   <span style="color: #000000; font-weight: bold;">function</span> ObjectToArray<span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$new_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ObjectToArray<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$new_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$new_array</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You can use this function exactly like the ArrayToObject function but you send an object instead of array.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/transform-arrays-objects-object-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Video Tutorial: How to create a Like/Unlike button with jQuery and PHP</title>
		<link>http://www.mlabs.info/create-likeunlike-button-jquery-php/</link>
		<comments>http://www.mlabs.info/create-likeunlike-button-jquery-php/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 21:50:41 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Video Tutorials]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=753</guid>
		<description><![CDATA[Hi here! In this video tutorial you&#8217;ll see how to create a simple like/unlike button using jQuery and PHP. Download the code here: http://etiny.info/ynjtqc Download the database here: http://etiny.info/yxhczc]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.mlabs.info/wp-content/uploads/2011/02/like-150x150.jpg" alt="" title="like" width="150" height="150" class="alignleft size-thumbnail wp-image-762" />Hi here!</p>
<p>In this video tutorial you&#8217;ll see how to create a simple like/unlike button using jQuery and PHP.</p>
<p><iframe title="YouTube video player" width="550" height="385" src="http://www.youtube.com/embed/KzzqJrrdL5o" frameborder="0" allowfullscreen></iframe></p>
<p>Download the code here: <a target="_blank" href="http://etiny.info/ynjtqc" target="_blank" rel="nofollow">http://etiny.info/ynjtqc</a><br />
Download the database here: <a target="_blank" href="http://etiny.info/yxhczc" target="_blank" rel="nofollow">http://etiny.info/yxhczc</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/create-likeunlike-button-jquery-php/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using PHP cookies</title>
		<link>http://www.mlabs.info/php-cookies/</link>
		<comments>http://www.mlabs.info/php-cookies/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 13:44:09 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php cookies]]></category>
		<category><![CDATA[setcookie]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=722</guid>
		<description><![CDATA[Awhile ago we&#8217;ve talked about handling sessions in PHP witch is used to store data for a short time. Now i&#8217;ll show you how to use cookies. The cookies are like sessions in a way. Cause they store data to, but for a long time (for how much you set) unlike sessions who&#8217;s deleted after [...]]]></description>
			<content:encoded><![CDATA[<p>Awhile ago we&#8217;ve talked about <a href="http://www.mlabs.info/handling-sessions-in-php/">handling sessions in PHP</a> witch is used to store data for a short time.</p>
<p>Now i&#8217;ll show you how to use cookies.</p>
<p>The cookies are like sessions in a way. Cause they store data to, but for a long time (for how much you set) unlike sessions who&#8217;s deleted after browser is closed.</p>
<p><strong>Creating a cookie and set it to expire in 1 hour:</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p722code63'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p72263"><td class="code" id="p722code63"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myFirstCookie&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'some value'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Creating a cookie and set it to expire in 30 days:</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p722code64'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p72264"><td class="code" id="p722code64"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myFirstCookie&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'some value'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Reading a cookie:</strong><br />
So the variable <em>$myCookie</em> will content &#8220;some value&#8221; <em>(the value that we&#8217;ve set above)</em></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p722code65'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p72265"><td class="code" id="p722code65"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$myCookie</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'myFirstCookie'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$myCookie</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Deleting a cookie:</strong><br />
To delete a cookie you will set it to one hour ago.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p722code66'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p72266"><td class="code" id="p722code66"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">setcookie</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myFirstCookie&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Good 2 know:</strong> Sometines IE6 doesn&#8217;t get the null cookie so you will have to set a value.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/php-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a file using PHP</title>
		<link>http://www.mlabs.info/create-file-php/</link>
		<comments>http://www.mlabs.info/create-file-php/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 13:03:50 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file create]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=701</guid>
		<description><![CDATA[Now i&#8217;ll show you how to create a file using PHP&#8217;s function fopen() Example: View Code PHP$fileName = 'myFirstFile.txt'; $fh = fopen&#40;$fileName, 'w'&#41; or die&#40;&#34;can't open file&#34;&#41;; fclose&#40;$fh&#41;; Explain: View Code PHP$fileName = 'myFirstFile.txt'; This is the file name and extension we will create. View Code PHP$fh = fopen&#40;$fileName, 'w'&#41; or die&#40;&#34;can't open file&#34;&#41;; This [...]]]></description>
			<content:encoded><![CDATA[<p>Now i&#8217;ll show you how to create a file using PHP&#8217;s function <strong>fopen()</strong></p>
<p><strong>Example:</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p701code71'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70171"><td class="code" id="p701code71"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fileName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'myFirstFile.txt'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fh</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileName</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;can't open file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
<strong>Explain:</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p701code72'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70172"><td class="code" id="p701code72"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fileName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'myFirstFile.txt'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is the file name and extension we will create.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p701code73'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70173"><td class="code" id="p701code73"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fh</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileName</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;can't open file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This function will open file but if the file doesn&#8217;t exist he will create it because we&#8217;ve put the write mode <em>(w)</em></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p701code74'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70174"><td class="code" id="p701code74"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We close the file that was opened above.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/create-file-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.mlabs.info @ 2012-02-04 17:38:04 -->
