<?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>Amoeba Solution Kiosk &#187; Programming Techniques</title> <atom:link href="http://ask.amoeba.co.in/topics/programming-techniques/feed/" rel="self" type="application/rss+xml" /><link>http://ask.amoeba.co.in</link> <description>Providing solutions for PHP, MySQL, Flash, Flex, Action Script, Javascript, YUI, JQuery, CSS, XHTML problems.</description> <lastBuildDate>Fri, 30 Dec 2011 18:12:55 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Compare two arrays in PHP using array_diff &#124; Check whether arrays are equal.</title><link>http://ask.amoeba.co.in/compare-two-arrays-in-php-using-array_diff-check-whether-arrays-are-equal/</link> <comments>http://ask.amoeba.co.in/compare-two-arrays-in-php-using-array_diff-check-whether-arrays-are-equal/#comments</comments> <pubDate>Tue, 07 Jun 2011 15:50:08 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[array]]></category> <category><![CDATA[array_diff]]></category> <category><![CDATA[compare]]></category> <category><![CDATA[function]]></category> <category><![CDATA[method]]></category> <category><![CDATA[php]]></category> <category><![CDATA[programming]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=166</guid> <description><![CDATA[You want to compare two arrays in PHP. Basically what you need is to make sure that both the arrays contain the same set of values may or may not be in the same order. You can use the built-in <strong>PHP </strong>function,<strong> array_diff </strong>to compute the difference of arrays. But this function just checks whether all the values of array1 is in array2 and if not returns the values which are not present in array2.]]></description> <content:encoded><![CDATA[<p>You want to compare two arrays in PHP. Basically what you need is to make sure that both the arrays contain the same set of values may or may not be in the same order. You can use the built-in <strong>PHP </strong>function,<strong> array_diff </strong>to compute the difference of arrays. But this function just checks whether all the values of array1 is in array2 and if not returns the values which are not present in array2.</p><p>Look at the code below.</p><pre class="brush: php; html-script: false; title: ; notranslate">
&lt;?php
$a = array(&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;green&quot;);
$b = array(&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;orange&quot;);
print_r(array_diff($b, $a));
?&gt;
</pre><p>This code returns a <strong>blank array</strong> because <strong>it could find all the elements in $a present in $b,</strong> <strong>though both arrays are different.</strong></p><p>So, just depending on a single array_diff function will not give you the intended result. Instead, use it like this,</p><pre class="brush: php; html-script: false; title: ; notranslate">
&lt;?php
$a = array(&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;green&quot;);
$b = array(&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;orange&quot;);
if(!count(array_diff($a, $b)) &amp;&amp; !count(array_diff($b, $a))) {
    // Arrays are equal
} else {
   // Array values are different
}
?&gt;
</pre><p>Hope this helps. Please let me know if you have any questions.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fcompare-two-arrays-in-php-using-array_diff-check-whether-arrays-are-equal%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/compare-two-arrays-in-php-using-array_diff-check-whether-arrays-are-equal/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/compare-two-arrays-in-php-using-array_diff-check-whether-arrays-are-equal/"  data-text="Compare two arrays in PHP using array_diff | Check whether arrays are equal." data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/compare-two-arrays-in-php-using-array_diff-check-whether-arrays-are-equal/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/compare-two-arrays-in-php-using-array_diff-check-whether-arrays-are-equal/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/compare-two-arrays-in-php-using-array_diff-check-whether-arrays-are-equal/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Short Circuit Evaluation and its Use and Advantages in PHP and JavaScript &#8211; IF-less Flow Control</title><link>http://ask.amoeba.co.in/short-circuit-evaluation-and-its-use-and-advantages-in-php-and-javascript-if-less-flow-control/</link> <comments>http://ask.amoeba.co.in/short-circuit-evaluation-and-its-use-and-advantages-in-php-and-javascript-if-less-flow-control/#comments</comments> <pubDate>Mon, 20 Sep 2010 11:16:56 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[Javascript & Libraries]]></category> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[boolean]]></category> <category><![CDATA[evaluation]]></category> <category><![CDATA[flow control]]></category> <category><![CDATA[if]]></category> <category><![CDATA[if-less]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[less code]]></category> <category><![CDATA[mccarthy]]></category> <category><![CDATA[minimal]]></category> <category><![CDATA[php]]></category> <category><![CDATA[shortcut]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=157</guid> <description><![CDATA[We call it Short Circuit Evaluation (also known as minimal evaluation, or McCarthy evaluation) when a programming language DOES NOT evaluate/execute the second operand in a condition. if the first operand alone can fully determine the outcome of that condition. We have been using this concept in our codes always. All PHP guys must be [...]]]></description> <content:encoded><![CDATA[<p>We call it <strong>Short Circuit Evaluation</strong> (also known as <strong>minimal evaluation</strong>, or <strong>McCarthy evaluation) </strong>when a programming language<strong> DOES NOT</strong> evaluate/execute the second operand in a condition. if the first operand alone can fully determine the outcome of that condition.</p><p>We have been using this concept in our codes always. All PHP guys must be familiar with this piece of code.</p><p><strong><span
style="font-size: x-small;"><span
style="color: #0000ff;">mysql_connect(localhost,$user,$password)  or die( &#8220;Unable to connect&#8221;);</span></span></strong></p><p>Yes, this is Short Circuit Evaluation! If the above code can connect to a mysql database successfully, the second operand &#8220;die&#8221; never gets executed. But if the <strong>mysql_connect </strong>function returns <strong>false</strong>, then the program <strong>dies</strong>.</p><p>Let&#8217;s take two examples to understand how it works:</p><p><span
style="color: #0000ff;"><strong>if ($_POST &amp;&amp; isset($_POST['name']) {<br
/> //Do something here<br
/> }</strong></span></p><p>This is an AND operation and the statements inside IF block will get executed only if both the conditions are TRUE (or Truthy &#8211; It doesn&#8217;t really have to be a boolean TRUE , but just need have a value other than any Falsy values). So there is no point in evaluating the second condition if the first one is <strong>False</strong>. It stops execution if $_POST is not defined and skip the IF block.</p><p><strong><span
style="color: #0000ff;">if ($password == &#8221;  || strlen($password) &lt; 4) {<br
/> //Throw error here<br
/> }</span></strong><br
/> Here the second operand will be only evaluated if the first condition is <strong>False </strong>that is when the <strong>$password</strong> variable is not blank.</p><p><strong>IF-less flow control.</strong><br
/> In both the above examples, we used IF blocks. But we can actually use this <strong>Short Circuit</strong> evaluation to get rid of <strong>IFs </strong>and <strong>Elses </strong>in our code. If you look at the code of many advanced programmers, you can see that they use this Short Circuit Evaluation method to write small and clean code.</p><p>The mysql_connect example at the top is an example for OR Short Cut. Another example:</p><p><span
style="color: #0000ff;"><strong>$from &amp;&amp; $to &amp;&amp; $msg &amp;&amp; sendMail();</strong></span></p><p>This code is equal to,</p><p><strong><span
style="color: #0000ff;">if ($from &amp;&amp; $to &amp;&amp; $msg) {<br
/> sendMail();<br
/> }</span></strong></p><p>In PHP a conditional expression only returns Boolean values. So the Result Type of these Short Cut operators are known as Boolean. See this example.</p><p><span
style="color: #0000ff;"><strong>$name = &#8216;John&#8217;;</strong></span><br
/> <span
style="color: #0000ff;"><strong>$title = $name || &#8220;no name&#8221;;<br
/> echo $title;</strong></span></p><p>$title will hold a value of <strong>1</strong> because the expression returned a True Result.  Even if the <strong>$name</strong> is false, the <strong>$title</strong> will hold a value of 1.</p><p>But in JavaScript, a conditional expression returns the last evaluated sub expression.</p><p>So the <strong>Javascript </strong>version of the above code would be different.</p><p><span
style="color: #0000ff;"><strong>var name = &#8216;John&#8217;;</strong></span><br
/> <span
style="color: #0000ff;"><strong>var title = name || &#8220;no name&#8221;;<br
/> alert(title);</strong></span></p><p>This will alert &#8220;John&#8221; hence javascript returns the Last Value evaluated. This feature allows us to write more simple and cleaner code in Javascript.</p><p><span
style="color: #0000ff;"><strong>var name = &#8216;John&#8217;;</strong></span><br
/> <span
style="color: #0000ff;"><strong>var title = name &amp;&amp; &#8220;no name&#8221;;<br
/> alert(title);</strong></span></p><p>The above example (a stupid example) will alert &#8220;no name&#8221; because, the first operand &#8220;name&#8221; is Truthy and it moves on to evaluate the second expression and returns it as the &#8220;Last Value&#8221; regardless of the evaluation result.</p><p>Do more. Write Less. <img
src='http://ask.amoeba.co.in/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fshort-circuit-evaluation-and-its-use-and-advantages-in-php-and-javascript-if-less-flow-control%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/short-circuit-evaluation-and-its-use-and-advantages-in-php-and-javascript-if-less-flow-control/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/short-circuit-evaluation-and-its-use-and-advantages-in-php-and-javascript-if-less-flow-control/"  data-text="Short Circuit Evaluation and its Use and Advantages in PHP and JavaScript &#8211; IF-less Flow Control" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/short-circuit-evaluation-and-its-use-and-advantages-in-php-and-javascript-if-less-flow-control/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/short-circuit-evaluation-and-its-use-and-advantages-in-php-and-javascript-if-less-flow-control/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/short-circuit-evaluation-and-its-use-and-advantages-in-php-and-javascript-if-less-flow-control/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>HTML5 Canvas Tutorial &amp; Example. Draw a Rainbow using Arc.</title><link>http://ask.amoeba.co.in/html5-canvas-tutorial-example-draw-a-rainbow-using-arc/</link> <comments>http://ask.amoeba.co.in/html5-canvas-tutorial-example-draw-a-rainbow-using-arc/#comments</comments> <pubDate>Fri, 17 Sep 2010 16:45:54 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[CSS & XHTML]]></category> <category><![CDATA[Javascript & Libraries]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[Web 3.0]]></category> <category><![CDATA[arc]]></category> <category><![CDATA[browser]]></category> <category><![CDATA[canvas]]></category> <category><![CDATA[context]]></category> <category><![CDATA[demo]]></category> <category><![CDATA[draw]]></category> <category><![CDATA[example]]></category> <category><![CDATA[explorer canvas]]></category> <category><![CDATA[graphics]]></category> <category><![CDATA[html5]]></category> <category><![CDATA[marijn haverbeke]]></category> <category><![CDATA[rainbow]]></category> <category><![CDATA[tutorial]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=153</guid> <description><![CDATA[The world is slowly adopting HTML5 and it is time to move towards it. HTML5 incorporates many features which were achievable only using third party plug-ins. I am not talking about HTML5 in detail. I just want to give you some light on a great feature which HTML5 ships with, &#8220;Canvas&#8221;! &#8220;Canvas&#8221; which is an [...]]]></description> <content:encoded><![CDATA[<p>The world is slowly adopting HTML5 and it is time to move towards it. HTML5 incorporates many features which were achievable only using third party plug-ins. I am not talking about HTML5 in detail. I just want to give you some light on a great feature which HTML5 ships with, &#8220;Canvas&#8221;!</p><p>&#8220;Canvas&#8221; which is an HTML5 tag, allows you to render graphics or visual images on the fly through programming in a browser. Very similar to generating graphics (drawing shapes) in Flash using the BitmapData class. To implement canvas in your webpage, you need to define a &#8220;canvas&#8221; tag in your mark up just like how you define any other container tag like &#8220;div&#8221;.</p><pre class="brush: xml; title: ; notranslate">
&lt;canvas id=&quot;myCanvas&quot; width=&quot;500&quot; height=&quot;200&quot;&gt;&lt;/canvas&gt;
</pre><p>A canvas object contains a drawing context, which is where we draw graphics. This context can be accessed using Javascript. HTML5 has now defined only a &#8220;2D&#8221; context in a canvas. The future release of HTML5 may contain a 3D context as well. Let&#8217;s now see how to access this 2D context and start drawing.</p><pre class="brush: jscript; title: ; notranslate">
&lt;script&gt;
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
&lt;/script&gt;
</pre><p>The context has many methods associated with it which allows us to draw various shapes, fill colors, define styles etc. See the example below which draws a Rainbow in a Canvas. The rainbow is created by drawing 7 circles with different radiuses. You don&#8217;t see the full circles because I didn&#8217;t define a height for the canvas. The canvas has now the default height and it crops the rest of the part. Play with the code and let me know if you have any questions.</p><pre class="brush: php; html-script: true; title: ; notranslate">
&lt;html&gt;
&lt;body&gt;
&lt;canvas id=&quot;myCanvas&quot;&gt;&lt;/canvas&gt;
&lt;script&gt;
var canvas = document.getElementById('myCanvas');
canvas.width = width = 470;
var context = canvas.getContext('2d');
var drawCircle = function(color, x, y, radius){
  context.arc(x, y, radius, 0, Math.PI*2, 0);
  context.fillStyle = '#' + 'ceff99ff78f86eeaaffffd45333'.substr(color*3,3);
  context.fill();
  context.beginPath();
};
for(i=0; i&lt;7; i++){
	drawCircle(i%7, width/2, width/2, 250-15*(i+1));
}
&lt;/script&gt;
&lt;/body&gt;
</pre><p>The best part about the canvas is that, you can save a rendered graphics in the browser as an image by choosing Save Image As from the canvas context menu. I am not sure this feature is available in all the browsers.</p><p>Among the versions in Internet Explorer, IE 9 is the only browser which supports HTML5 and canvas. Other Major browsers have been supporting HTML5 for quite a while. To enable canvas feature in IE7+, developers can include a JS library named <strong>Explorer Canvas</strong> in their code. Download it here: <a
href="http://code.google.com/p/explorercanvas/downloads/detail?name=excanvas_r3.zip">http://code.google.com/p/explorercanvas/downloads/detail?name=excanvas_r3.zip</a></p><p>The above example code is a simplified version of code written by Marijn Haverbeke.<br
/> For a complete documentation on Canvas, see <a
href="https://developer.mozilla.org/en/Canvas_tutorial/Drawing_shapes">https://developer.mozilla.org/en/Canvas_tutorial/Drawing_shapes</a></p><p>Enjoy!</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fhtml5-canvas-tutorial-example-draw-a-rainbow-using-arc%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/html5-canvas-tutorial-example-draw-a-rainbow-using-arc/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/html5-canvas-tutorial-example-draw-a-rainbow-using-arc/"  data-text="HTML5 Canvas Tutorial &#038; Example. Draw a Rainbow using Arc." data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/html5-canvas-tutorial-example-draw-a-rainbow-using-arc/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/html5-canvas-tutorial-example-draw-a-rainbow-using-arc/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/html5-canvas-tutorial-example-draw-a-rainbow-using-arc/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>How to Protect your SWF (AS2 or AS3). Prevent SWF Decompile using SWF Protector</title><link>http://ask.amoeba.co.in/how-to-protect-your-swf-as2-or-as3-prevent-swf-decompile-using-swf-protector/</link> <comments>http://ask.amoeba.co.in/how-to-protect-your-swf-as2-or-as3-prevent-swf-decompile-using-swf-protector/#comments</comments> <pubDate>Wed, 01 Sep 2010 16:01:04 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[Flash & Action Script]]></category> <category><![CDATA[Flex]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[action script]]></category> <category><![CDATA[as2]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[dcomsoft]]></category> <category><![CDATA[decomipler]]></category> <category><![CDATA[decompile]]></category> <category><![CDATA[encryption]]></category> <category><![CDATA[obfuscate]]></category> <category><![CDATA[obfuscation]]></category> <category><![CDATA[php]]></category> <category><![CDATA[protection]]></category> <category><![CDATA[solution]]></category> <category><![CDATA[sothink]]></category> <category><![CDATA[swf]]></category> <category><![CDATA[swfprotector]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=150</guid> <description><![CDATA[Being a flash programmer, I have always had this concern. The way a flash application works differs from a php application. We don’t really need to worry about protecting the PHP code because the code is interpreted in the server and only the html codes are sent to the client browser. But a Flash engine basically lies in the user browser and the AS2 or AS3 codes are rendered in the user Browser. Though a Flash application is compiled in to a compact SWF file which is served to the user, this file contains all the codes we have written, thus making it easy for hackers or other developers to steal codes from our SWF application. And the Actionscript code is the most important part of any Flash/Flex application.]]></description> <content:encoded><![CDATA[<p>Being a flash programmer, I have always had this concern. The way a flash application works differs from a php application. We don’t really need to worry about protecting the PHP code because the code is interpreted in the server and only the html codes are sent to the client browser. But a Flash engine basically lies in the user browser and the AS2 or AS3 codes are rendered in the user Browser. Though a Flash application is compiled in to a compact SWF file which is served to the user, this file contains all the codes we have written, thus making it easy for hackers or other developers to steal codes from our SWF application. And the Actionscript code is the most important part of any Flash/Flex application.</p><p>I normally share codes I write with the developer community. But there are occasions when I don’t want others to see the source code of my application. This could be when I have concerns over the security of my application or when it is a proprietary application built for a customer.  But unfortunately stealing the source code of a Flash SWF application is very easy. With reverse engineering technologies gaining popularity day by day among the Flash development communities, protecting the Actionscript code is a big problem. There are plenty of SWF decompilers like Sothink available in the market making it easy for anyone to decompile an SWF file fetched from a browser and see the whole source code written for the application.</p><p>This is when we need to really think about code security and protecting our source codes from being stolen. There are some flash protector applications available and I tried SWF Protector from DComSoft. It works out really well. The application is available for Windows, Mac and Linux. Protecting an SWF application using the SWF Protector is really easy. Add your SWF files to the SWF Protector and click on the Protect All button. The SWF Protector uses different algorithms for AS2 and AS3 versions. For AS2, it uses “Mix Script” and “Mask Script” methods which basically mix up functions, arguments and variables names, so it becomes difficult for understanding after de-compilation. For AS3, the code can be “Protected” which modifies the scripts in such way that SWF files can play in Flash player, but cannot be decompiled, or “Obfuscated” which renames variable and other objects in the code making it impossible to compile the code further.</p><p>There is another method to protect your SWF code without using any application. That is by creating a loader SWF which will embed the actual SWF as a byteArray and it can be loaded using  Loader.loadBytes().</p><p>When someone tries to decomplile an SWF file which is protected using SWF Protector the code would look something like this.</p><pre class="brush: as3; title: ; notranslate">
do {
// unexpected jump
} while (true);
// swfAction0xAD hexdata 0x52,0x17,0x99,0x02,0x00,0x39,0x00,0x9A,0x01,0x00,0x00,0x99... // Unknown action
}
&quot;holder1&quot;.holder1.loadMovie();
// unexpected jump
/* Error1016 */
// unexpected jump
do {
(this);// not popped
if (true) {
// unexpected jump
} while (this);
(this);// not popped
// unexpected jump
}
}
}
Set(&quot;\x0B\x1A\x13\x16&quot;, true);
} while (true);
</pre><p>Now you say, would this be useful for someone? No, of course!</p><p>The SWF Protector is not free but comes with a small price tag. But it’s more than worth the money you pay and better than concerning over the security of your code. You can get more information or buy this tool from <a
href="http://www.dcomsoft.com/" target="_blank">http://www.dcomsoft.com</a></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fhow-to-protect-your-swf-as2-or-as3-prevent-swf-decompile-using-swf-protector%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/how-to-protect-your-swf-as2-or-as3-prevent-swf-decompile-using-swf-protector/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/how-to-protect-your-swf-as2-or-as3-prevent-swf-decompile-using-swf-protector/"  data-text="How to Protect your SWF (AS2 or AS3). Prevent SWF Decompile using SWF Protector" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/how-to-protect-your-swf-as2-or-as3-prevent-swf-decompile-using-swf-protector/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/how-to-protect-your-swf-as2-or-as3-prevent-swf-decompile-using-swf-protector/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/how-to-protect-your-swf-as2-or-as3-prevent-swf-decompile-using-swf-protector/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>PHP &#8211; Search in an Array for Values Matching a Pattern &#8211; Regex, Wildcard</title><link>http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/</link> <comments>http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/#comments</comments> <pubDate>Wed, 07 Jul 2010 14:22:13 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[Regular Expression]]></category> <category><![CDATA[array]]></category> <category><![CDATA[array_search]]></category> <category><![CDATA[in_array]]></category> <category><![CDATA[pattern]]></category> <category><![CDATA[php]]></category> <category><![CDATA[preg_grep]]></category> <category><![CDATA[regex]]></category> <category><![CDATA[search in array]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=140</guid> <description><![CDATA[I have an array with many values and I need to do a search to find all the values that match a pattern. We have functions like in_array &#38; array_search in PHP, but these functions basically try to match the exact needle value in the array. I need to use my Regular Expression Pattern and [...]]]></description> <content:encoded><![CDATA[<p>I have an array with many values and I need to do a search to find all the values that match a pattern. We have functions like <strong>in_array</strong> &amp; <strong>array_search</strong> in PHP, but these functions basically try to match the exact needle value in the array. I need to use my <strong>Regular Expression Pattern</strong> and find all the array values that match the regex pattern.</p><p>The PHP function <strong>preg_grep</strong> handles this beautifully. It accepts the <strong>Regex </strong>pattern and the array to search for as its parameters. It then returns the array consisting of the elements of the input array that match the given pattern. The returned array is indexed using the keys from the input array.</p><p>Here is my array:<br
/> Array<br
/> (<br
/> [0] =&gt; Armenia<br
/> [1] =&gt; America<br
/> [2] =&gt; Algeria<br
/> [3] =&gt; India<br
/> [4] =&gt; Brazil<br
/> [5] =&gt; Croatia<br
/> [6] =&gt; Denmark<br
/> )<br
/> I want to find all the countries in the array which start with the letter &#8216;A&#8217;. We need to form a regular expression which will match all the strings starting with letter A.</p><p>I have got this simple regular expression: <strong>&#8216;/^A.*/&#8217;</strong></p><p>Now here is the PHP code to find the values from the Array.</p><pre class="brush: php; html-script: true; title: ; notranslate">
&lt;?php
$array = array('Armenia', 'America', 'Algeria', 'India', 'Brazil', 'Croatia', 'Denmark');
$fl_array = preg_grep('/^A.*/', $array);
echo '&lt;pre&gt;';
print_r($fl_array);
echo '&lt;/pre&gt;';
?&gt;
</pre><p>Which then gives you this output:<br
/> Array<br
/> (<br
/> [0] =&gt; Armenia<br
/> [1] =&gt; America<br
/> [2] =&gt; Algeria<br
/> )</p><p>Here are some Regular Expression Patterns you could use.</p><p>Find whole numbers: <strong>&#8216;/^\d+$/&#8217;</strong><br
/> Floating numbers: <strong>&#8216;/^\d+\.{1}\d+$/&#8217;</strong><br
/> Lowercase Words: <strong>&#8216;/^[a-z]+$/&#8217; </strong></p><p>Play with Regular Expressions and let me know if you have any questions or if you need more patterns. I am planning to publish an article on Regular Expressions soon.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fphp-search-in-an-array-for-values-matching-a-pattern-regex-wildcard%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/"  data-text="PHP &#8211; Search in an Array for Values Matching a Pattern &#8211; Regex, Wildcard" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>PHP &#8211; How to Get Browser Properties and Capabilities &#8211; get_browser()</title><link>http://ask.amoeba.co.in/php-how-to-get-browser-properties-and-capabilities-get_browser/</link> <comments>http://ask.amoeba.co.in/php-how-to-get-browser-properties-and-capabilities-get_browser/#comments</comments> <pubDate>Thu, 01 Jul 2010 12:18:15 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[Enterprise Web]]></category> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[browscap]]></category> <category><![CDATA[browscap.ini]]></category> <category><![CDATA[browser capability]]></category> <category><![CDATA[browser properties]]></category> <category><![CDATA[gary keith]]></category> <category><![CDATA[get_browser]]></category> <category><![CDATA[http_user_agent]]></category> <category><![CDATA[ini]]></category> <category><![CDATA[ismobiledevice]]></category> <category><![CDATA[is_mobile_device]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[mobile application]]></category> <category><![CDATA[php]]></category> <category><![CDATA[php.ini]]></category> <category><![CDATA[web]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=136</guid> <description><![CDATA[In this tutorial, learn about the get_browser() PHP function and its configuration. We'll learn how to use Gary Keith's browser information database (browscap.ini)  with the PHP browscap directive.
I wanted one of my web applications to have a different appearance on mobile phones and devices. I didn't really want to set up an entirely different domain or use a sub domain particularly for mobile devices (like http://mobile.facebook.com). Instead I want to tackle the device inside my application logic so that all users access the same URL.]]></description> <content:encoded><![CDATA[<p>In this tutorial, learn about the<strong> get_browser()</strong> PHP function and its configuration. We&#8217;ll learn how to use Gary Keith&#8217;s browser information database <strong>(<a
title="A special version of browscap.ini for PHP users " rel="nofollow" href="http://browsers.garykeith.com/downloads.asp" target="_blank">browscap.ini</a>)</strong> with the <strong>PHP browscap directive</strong>.</p><p>I wanted one of my web applications to have a different appearance on mobile phones and devices. I didn&#8217;t really want to set up an entirely different domain or use a sub domain particularly for mobile devices (like http://mobile.facebook.com). Instead I want to tackle the device inside my application logic so that all users access the same URL.</p><p>PHP&#8217;s <span
style="color: #000080;"><strong>$_SERVER['HTTP_USER_AGENT']</strong></span> is cool. You can play around this variable and achieve what you want. But you don&#8217;t get all you want. Let&#8217;s look at the string output of the above variable on my browser:</p><p><strong><em><span
style="color: #993300;">Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6)  Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)</span><br
/> </em></strong></p><p>This gives you some information. I wanted an easy way to see whether the request was from a mobile device.</p><p>PHP has this function, <strong>get_browser</strong> which attempts to determine the capabilities of the  user&#8217;s browser, by looking up the browser&#8217;s information in the <strong><var>browscap.ini</var></strong> file.</p><p>In order for this to work, your <strong>browscap </strong>configuration setting  in <strong><var>php.ini</var></strong> must point to the correct location of the <var>browscap.ini</var> file on your system. <var>browscap.ini</var> is not bundled with PHP, but you may find an  up-to-date <a
title="Link : http://browsers.garykeith.com/downloads.asp" href="http://browsers.garykeith.com/downloads.asp" target="_blank">» php_browscap.ini</a> file  here. While <var>browscap.ini</var> contains information on  many browsers, it relies on user updates to keep the database current.</p><p>First, Download the browscap.ini file for PHP from the above website. There are many files and this is the one you need: <strong><a
title="Gary Keith's browscap.ini for PHP" href="http://browsers.garykeith.com/stream.asp?PHP_BrowsCapINI" target="_blank">Gary Keith&#8217;s browscap.ini for PHP</a></strong></p><p>Now, open your PHP.ini file and find for &#8220;browscap&#8221;. You will see something like this:</p><p><span
style="color: #993300;"><strong>[browscap]<br
/> ;browscap = extras\browscap.ini</strong></span></p><p>Remove the semicolon and change the path to point to the <strong>php_browscap.ini</strong> you just downloaded. Your PHP.ini directive now looks like this:</p><p><span
style="color: #993300;"><strong>[browscap]<br
/> browscap = C:\Inetpub\PHP5\extras\php_browscap.ini</strong></span></p><p>Save the PHP.ini file and restart your Web server.</p><p>Now use the get_browser function in your PHP code to get user&#8217;s browser properties and capabilities.</p><pre class="brush: php; html-script: false; title: ; notranslate">
&lt;?php
$browser = get_browser(null, true);
echo &quot;&lt;pre&gt;&quot;;
print_r($browser);
echo &quot;&lt;/pre&gt;&quot;;
?&gt;
</pre><p>This is the output I got when I accessed the script using a Computer Browser.</p><pre class="brush: php; html-script: false; title: ; notranslate">
Array
(
    [browser_name_regex] =&gt; ^mozilla/5\.0 (windows; .*; windows nt 5\.1; .*; rv:1\.9\.2.*) gecko/.* firefox/3\.6.*$
    [browser_name_pattern] =&gt; Mozilla/5.0 (Windows; *; Windows NT 5.1; *; rv:1.9.2*) Gecko/* Firefox/3.6*
    [parent] =&gt; Firefox 3.6
    [platform] =&gt; WinXP
    [win32] =&gt; 1
    [browser] =&gt; Firefox
    [version] =&gt; 3.6
    [majorver] =&gt; 3
    [minorver] =&gt; 6
    [frames] =&gt; 1
    [iframes] =&gt; 1
    [tables] =&gt; 1
    [cookies] =&gt; 1
    [javaapplets] =&gt; 1
    1 =&gt; 1
    [cssversion] =&gt; 3
    [supportscss] =&gt; 1
    [alpha] =&gt;
    [beta] =&gt;
    [win16] =&gt;
    [win64] =&gt;
    [backgroundsounds] =&gt;
    [cdf] =&gt;
    [vbscript] =&gt;
    [activexcontrols] =&gt;
    [isbanned] =&gt;
    [ismobiledevice] =&gt;
    [issyndicationreader] =&gt;
    [crawler] =&gt;
    [aol] =&gt;
    [aolversion] =&gt; 0
)
</pre><p>When I accessed the same script using a mobile phone, here&#8217;s what I got:</p><pre class="brush: php; html-script: false; title: ; notranslate">
Array
(
    [browser_name_regex] =&gt; ^.*nokia.*/.*$
    [browser_name_pattern] =&gt; *Nokia*/*
    [parent] =&gt; Nokia
    [browser] =&gt; Nokia
    [tables] =&gt; 1
    [cookies] =&gt; 1
    [ismobiledevice] =&gt; 1
    [version] =&gt; 0
    [majorver] =&gt; 0
    [minorver] =&gt; 0
    [platform] =&gt; unknown
    [frames] =&gt;
    [iframes] =&gt;
    [javaapplets] =&gt;
    1 =&gt;
    [cssversion] =&gt; 0
    [supportscss] =&gt;
    [alpha] =&gt;
    [beta] =&gt;
    [win16] =&gt;
    [win64] =&gt;
    [backgroundsounds] =&gt;
    [cdf] =&gt;
    [vbscript] =&gt;
    [activexcontrols] =&gt;
    [isbanned] =&gt;
    [ismobiledevice] =&gt;
    [issyndicationreader] =&gt;
    [crawler] =&gt;
    [aol] =&gt;
    [aolversion] =&gt; 0
)
</pre><p>I was just looking at this,</p><pre><span style="color: #993300;"><strong>[ismobiledevice] =&gt; 1</strong></span>
Interesting uh!</pre><p>If your shared hosting service doesn&#8217;t allow you to modify the PHP.INI file, you would want to use a stand alone implementation of the same concept by Jonathan. <a
href="http://code.google.com/p/phpbrowscap/">http://code.google.com/p/phpbrowscap/ </a></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fphp-how-to-get-browser-properties-and-capabilities-get_browser%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/php-how-to-get-browser-properties-and-capabilities-get_browser/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/php-how-to-get-browser-properties-and-capabilities-get_browser/"  data-text="PHP &#8211; How to Get Browser Properties and Capabilities &#8211; get_browser()" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/php-how-to-get-browser-properties-and-capabilities-get_browser/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/php-how-to-get-browser-properties-and-capabilities-get_browser/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/php-how-to-get-browser-properties-and-capabilities-get_browser/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>CakePHP &#8211; Search for records between two dates inclusively</title><link>http://ask.amoeba.co.in/cakephp-search-for-records-between-two-dates-inclusively/</link> <comments>http://ask.amoeba.co.in/cakephp-search-for-records-between-two-dates-inclusively/#comments</comments> <pubDate>Fri, 25 Jun 2010 13:45:10 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[CakePHP]]></category> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[app import]]></category> <category><![CDATA[between]]></category> <category><![CDATA[date]]></category> <category><![CDATA[dayassql]]></category> <category><![CDATA[daysassql]]></category> <category><![CDATA[from]]></category> <category><![CDATA[helper]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[php]]></category> <category><![CDATA[query]]></category> <category><![CDATA[search]]></category> <category><![CDATA[time]]></category> <category><![CDATA[time helper]]></category> <category><![CDATA[to]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=132</guid> <description><![CDATA[Often we search for records in a database table for fetching records that were created or modified on a particular date or between two dates. We match against a date field and add multiple conditions to find records with a date field value ranging between two dates. It would look something like this: Select * [...]]]></description> <content:encoded><![CDATA[<p>Often we search for records in a database table for fetching records that were created or modified on a particular date or between two dates. We match against a date field and add multiple conditions to find records with a date field value ranging between two dates.</p><p>It would look something like this:<br
/> <code>Select * from tables where CREATE_TIME &gt;=  "2007-03-14 00:00:00<code>" and CREATE_TIME &lt;= "2007-03-16 23:59:59"</code></code></p><p>CakePHP has built-in functions to format a query like this if you have two dates, the FROM DATE and the TO DATE.</p><p>See the Example below:</p><pre class="brush: php; html-script: true; title: ; notranslate">
$from = '14-Mar-2007';
$to = '16-03-2007';
App::import('Helper', 'Time');
$time = new TimeHelper();
echo '('.$time-&gt;daysAsSql(($from)?$from:$to, ($to)?$to:$from, &quot;created&quot;).')';
</pre><p>In this example, we have two variables to store FROM and TO date limits. The function we used here is &#8220;daysAsSql&#8217; and its a method available with the Time Helper Class. Basically these helper functions are designed to use in Views. When we need to use Helper functions in  a Controller, we import the Helper using the App:import function.</p><p>After importing the Time Helper into your controller, create an instance of the Time Helper, <strong>$time = new TimeHelper();</strong></p><p>Now call this function by passing the date ranges and the field name as parameters. <strong>$time-&gt;daysAsSql(($from)?$from:$to,  ($to)?$to:$from, &#8220;date_field&#8221;)</strong><br
/> I have additional calculations here:<strong> ($from)?$from:$to</strong> &amp;<strong> ($to)?$to:$from</strong>. This makes sure that, if one of the date input values are null or not defined, it searches all the records with the date_field value on a particular day. Explained below.</p><p>The above example outputs this:</p><p>((created &gt;= &#8217;2007-03-14 00:00:00&#8242;) AND (created &lt;= &#8217;2007-03-16  23:59:59&#8242;))</p><p>Now you can use this as a Condition in your Find functions or as a Filter in your Pagination queries.</p><p>Examples:</p><pre class="brush: php; html-script: true; title: ; notranslate">
$filters = array();
$filters = '('.$time-&gt;daysAsSql(($from)?$from:$to, ($to)?$to:$from, &quot;created&quot;).')';
$records = $this-&gt;paginate('ModelName', $filters);
</pre><p>or</p><pre class="brush: php; html-script: true; title: ; notranslate">
$conditions = array();
$conditions = '('.$time-&gt;daysAsSql(($from)?$from:$to, ($to)?$to:$from,  &quot;created&quot;).')';
$this-&gt;data = $this-&gt;ModelName-&gt;find('all', array('conditions' =&amp;gt; $conditions));
</pre><p>If $from was null the query generated would look like this:<br
/> ((created &gt;= &#8217;2007-03-16 00:00:00&#8242;) AND (created &lt;= &#8217;2007-03-16   23:59:59&#8242;))</p><p>Please let me know if you have any questions.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fcakephp-search-for-records-between-two-dates-inclusively%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/cakephp-search-for-records-between-two-dates-inclusively/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/cakephp-search-for-records-between-two-dates-inclusively/"  data-text="CakePHP &#8211; Search for records between two dates inclusively" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/cakephp-search-for-records-between-two-dates-inclusively/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/cakephp-search-for-records-between-two-dates-inclusively/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/cakephp-search-for-records-between-two-dates-inclusively/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Swap Values Without Temp or A Third Variable in PHP</title><link>http://ask.amoeba.co.in/swap-values-without-temp-or-a-third-variable-in-php/</link> <comments>http://ask.amoeba.co.in/swap-values-without-temp-or-a-third-variable-in-php/#comments</comments> <pubDate>Wed, 02 Jun 2010 14:02:46 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[php]]></category> <category><![CDATA[swap]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=126</guid> <description><![CDATA[When we need to swap the values of two variables, we use a third variable temporarily to hold the data between swapping.  Something like this: Here is another way without using a temp or a third variable. And if you want to make it a function: Tweet]]></description> <content:encoded><![CDATA[<p>When we need to swap the values of two variables, we use a third variable temporarily to hold the data between swapping.  Something like this:</p><pre class="brush: php; html-script: true; title: ; notranslate">
&lt;?php
$tmp = $a;
$a = $b;
$b = $tmp;
?&gt;
</pre><p>Here is another way without using a temp or a third variable.</p><pre class="brush: php; html-script: true; title: ; notranslate">
&lt;?php
list($b, $a) = array($a, $b);
?&gt;
</pre><p>And if you want to make it a function:</p><pre class="brush: php; html-script: true; title: ; notranslate">
&lt;?php
function swapValues(&amp;$a, &amp;$b) {
     list($b, $a) = array($a, $b);
 }
$a = 10;
$b = 20;
swapValues($a, $b);
?&gt;
</pre><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fswap-values-without-temp-or-a-third-variable-in-php%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/swap-values-without-temp-or-a-third-variable-in-php/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/swap-values-without-temp-or-a-third-variable-in-php/"  data-text="Swap Values Without Temp or A Third Variable in PHP" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/swap-values-without-temp-or-a-third-variable-in-php/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/swap-values-without-temp-or-a-third-variable-in-php/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/swap-values-without-temp-or-a-third-variable-in-php/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>CakePHP &#8211; Auth Login Redirect Problem with Plugins</title><link>http://ask.amoeba.co.in/cakephp-auth-login-redirect-problem-with-plugins/</link> <comments>http://ask.amoeba.co.in/cakephp-auth-login-redirect-problem-with-plugins/#comments</comments> <pubDate>Wed, 02 Jun 2010 13:34:43 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[CakePHP]]></category> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[auth]]></category> <category><![CDATA[auth component]]></category> <category><![CDATA[loginaction]]></category> <category><![CDATA[php]]></category> <category><![CDATA[plugin]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=122</guid> <description><![CDATA[The Auth Component in CakePHP redirects the user to the log-in page when a user tries to access any protected pages in the application. The default log-in page is set by defining the loginAction variable in the beforeFilter function in your UsersController or AppController. But if you have used plug-ins in your application, and if [...]]]></description> <content:encoded><![CDATA[<p>The <strong>Auth Component</strong> in CakePHP redirects the user to the log-in page when a user tries to access any protected pages in the application. The default log-in page is set by defining the <strong>loginAction </strong>variable in the <strong>beforeFilter </strong>function in your <strong>UsersController </strong>or <strong>AppController</strong>.</p><p>But if you have used plug-ins in your application, and if a user tries to access a controller action of a plug-in the user is redirected to an invalid page like this.</p><p><strong>http://domain.com/plugin_name/users/login</strong></p><p>This is because, CakePHP assumes the user controller to be a a part of the Plug-in.</p><p>Normally, your beforeFilter function could look like this.</p><pre class="brush: php; html-script: true; title: ; notranslate">
function beforeFilter() {
	Security::setHash('md5');
	$this-&gt;Auth-&gt;loginAction = array('controller' =&gt; 'users', 'action' =&gt; 'login');
	$this-&gt;Auth-&gt;loginRedirect = array('controller' =&gt; 'home', 'action' =&gt; 'index');
	$this-&gt;Auth-&gt;loginError = 'Invalid Username or Password.';
	$this-&gt;Auth-&gt;authError = &quot;You are not authorized to access.&quot;;
	$this-&gt;Auth-&gt;logoutRedirect = array('controller' =&gt; 'users', 'action' =&gt; 'login');
}
</pre><p>The redirection problem can be avoided by defining the loginAction in the above function like this:</p><p><strong>$this-&gt;Auth-&gt;loginAction = array(&#8216;controller&#8217; =&gt; &#8216;users&#8217;, &#8216;action&#8217; =&gt; &#8216;login&#8217;, <span
style="color: #ff0000;">&#8216;plugin&#8217; =&gt; null</span>);</strong></p><p>This tells CakePHP that the user controller is a global controller.</p><p>The same problem occurs when you use <strong>$html-&gt;link or $html-&gt;url</strong> to generate links to global contoller actions from a plugin view. If you didn&#8217;t define the parameter <span
style="color: #ff0000;">&#8216;plugin&#8217;=&gt;true</span> in <strong>$html-&gt;link or $html-&gt;url</strong>, CakePHP will assume the controller to be a part of the current plugin and will try to access a controller within the plugin instead of redirecting the user to the global controller.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fcakephp-auth-login-redirect-problem-with-plugins%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/cakephp-auth-login-redirect-problem-with-plugins/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/cakephp-auth-login-redirect-problem-with-plugins/"  data-text="CakePHP &#8211; Auth Login Redirect Problem with Plugins" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/cakephp-auth-login-redirect-problem-with-plugins/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/cakephp-auth-login-redirect-problem-with-plugins/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/cakephp-auth-login-redirect-problem-with-plugins/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Convert under_scored strings to CamelCased without RegEx in PHP</title><link>http://ask.amoeba.co.in/convert-under_scored-strings-to-camelcased-without-regex-in-php/</link> <comments>http://ask.amoeba.co.in/convert-under_scored-strings-to-camelcased-without-regex-in-php/#comments</comments> <pubDate>Mon, 10 May 2010 08:15:45 +0000</pubDate> <dc:creator>Aneeska</dc:creator> <category><![CDATA[PHP/MySQL]]></category> <category><![CDATA[Programming Techniques]]></category> <category><![CDATA[array]]></category> <category><![CDATA[array_map]]></category> <category><![CDATA[CamelCase]]></category> <category><![CDATA[conversion]]></category> <category><![CDATA[php]]></category> <category><![CDATA[string]]></category> <guid
isPermaLink="false">http://ask.amoeba.co.in/?p=106</guid> <description><![CDATA[Developers normally use functions that use Regular Expression to convert under_scored strings in to CamelCased strings. Usage of Regular Expression is quite heavy. We can use a simple yet powerful method to convert these strings to CamelCase without using RegEx in PHP.]]></description> <content:encoded><![CDATA[<p>Developers normally use functions that use Regular Expression to convert <em><strong>under_scored</strong> </em>strings in to <em><strong>CamelCased</strong></em> strings. Usage of Regular Expression is quite heavy. We can use a simple yet powerful method to convert these strings to <strong>CamelCase </strong>without using RegEx in <strong>PHP</strong>.</p><p>Here is the method:</p><p><strong><span
style="color: #0000ff;">echo join</span>(<span
style="color: #ff0000;">&#8221;&#8221;</span>, <span
style="color: #0000ff;">array_map</span>(<span
style="color: #ff0000;">&#8220;ucwords&#8221;</span>, <span
style="color: #0000ff;">explode</span>(<span
style="color: #ff0000;">&#8216;_&#8217;,</span> $under_scored)));</strong></p><p>This combination of functions, first explodes the underscored string in to an array containing sub strings formed by &#8220;_&#8221; delimiter and applies ucwords() function to each member of the array. ucwords() uppercases the first character of the string. These uppercased strings are again joined back to form a single string which is the CamelCased version of the actual string.</p><p>Please let me know if you have any questions.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fask.amoeba.co.in%2Fconvert-under_scored-strings-to-camelcased-without-regex-in-php%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:65px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://ask.amoeba.co.in/convert-under_scored-strings-to-camelcased-without-regex-in-php/"></g:plusone></div><div
style="float:left; width:100px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://ask.amoeba.co.in/convert-under_scored-strings-to-camelcased-without-regex-in-php/"  data-text="Convert under_scored strings to CamelCased without RegEx in PHP" data-count="horizontal" data-via="aneesme">Tweet</a></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://ask.amoeba.co.in/convert-under_scored-strings-to-camelcased-without-regex-in-php/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://ask.amoeba.co.in/convert-under_scored-strings-to-camelcased-without-regex-in-php/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://ask.amoeba.co.in/convert-under_scored-strings-to-camelcased-without-regex-in-php/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
