<?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>WhileIf Blog</title>
	<atom:link href="http://www.whileifblog.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.whileifblog.com</link>
	<description>Programming, Computers and Stuff</description>
	<lastBuildDate>Tue, 21 Feb 2012 12:10:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ubuntu &#8211; How to Install MKVToolNix (Matroska tools) in Linux</title>
		<link>http://www.whileifblog.com/2012/02/21/ubuntu-how-to-install-mkvtoolnix-matroska-tools-in-linux/</link>
		<comments>http://www.whileifblog.com/2012/02/21/ubuntu-how-to-install-mkvtoolnix-matroska-tools-in-linux/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 12:10:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General Stuff]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mkv]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=731</guid>
		<description><![CDATA[Matroska is a new multimedia container format, based on EBML (Extensible Binary Meta Language), which is a kind of binary XML. MKVToolNix is cross-platform tools for Matroska. MKVToolnix recently released its 5.3.0 verison with following changes: 1. Several fields have &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/21/ubuntu-how-to-install-mkvtoolnix-matroska-tools-in-linux/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/21/ubuntu-how-to-install-mkvtoolnix-matroska-tools-in-linux/">Ubuntu &#8211; How to Install MKVToolNix (Matroska tools) in Linux</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><strong>Matroska</strong> is a new multimedia container format, based on <strong>EBML</strong> (Extensible Binary Meta Language), which is a kind of binary XML. <strong>MKVToolNix</strong> is cross-platform tools for <strong>Matroska</strong>.</p>
<p><strong>MKVToolnix</strong> recently released its 5.3.0 verison with following changes:</p>
<p>1. Several fields have been added to mkvmerge’s verbose identification output.<br />
2. File type identification and a segfault have been fixed for DTS files.<br />
3. File type detection for (E)AC3 files has been improved.<br />
4. mkvextract’s “timecodes_v2″ mode uses the same track IDs as mkvmerge’s identification mode outputs again.<br />
5. An invalid memory access with certain broken Matroska files has been fixed.<br />
6. mkvmerge can read input files as if they were part of a single huge file.<br />
7. mkvmerge can extract and use the audio encoder delay information stored in MP4 files as written by iTunes</p>
<p>To Install <strong>MKVToolNix</strong> in <strong>Ubuntu</strong>:</p>
<p>First to import public GPG key with this command:</p>
<pre class="brush: php; title: ; notranslate">
wget -O - http://www.bunkus.org/gpg-pub-moritzbunkus.txt | sudo apt-key add -
</pre>
<p>Then edit the source by:</p>
<pre class="brush: php; title: ; notranslate">
gksudo gedit /etc/apt/sources.list
</pre>
<p><span id="more-731"></span><br />
<strong>11.10 oneiric</strong> add following lines (other releases replace oneiric):</p>
<pre class="brush: plain; title: ; notranslate">
deb http://www.bunkus.org/ubuntu/oneiric/ ./
deb-src http://www.bunkus.org/ubuntu/oneiric/ ./
</pre>
<p>Now update and install MKVToolNix by:</p>
<pre class="brush: plain; title: ; notranslate">
sudo apt-get update
sudo apt-get install mkvtoolnix mkvtoolnix-gui
</pre>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2010/10/10/ubuntu-install-matroska-mkv-tools/" rel="bookmark" class="crp_title">Ubuntu &#8211; Install Matroska MKV tools</a></li><li><a href="http://www.whileifblog.com/2010/10/09/ubuntu-extract-content-from-mkv-files/" rel="bookmark" class="crp_title">Ubuntu &#8211; Extract content from MKV files</a></li><li><a href="http://www.whileifblog.com/2011/09/14/ubuntu-extract-audio-mp3-from-video-files-like-flv-mov-avi/" rel="bookmark" class="crp_title">Ubuntu &#8211; Extract audio mp3 from Video Files Like .flv, .mov, .avi</a></li><li><a href="http://www.whileifblog.com/2011/08/17/ubuntu-installing-virtualbox-guest-additions-with-kernel-modules/" rel="bookmark" class="crp_title">Ubuntu &#8211; Installing Virtualbox Guest Additions with Kernel modules</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/21/ubuntu-how-to-install-mkvtoolnix-matroska-tools-in-linux/">Ubuntu &#8211; How to Install MKVToolNix (Matroska tools) in Linux</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/21/ubuntu-how-to-install-mkvtoolnix-matroska-tools-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Magic Constants</title>
		<link>http://www.whileifblog.com/2012/02/20/php-magic-constants/</link>
		<comments>http://www.whileifblog.com/2012/02/20/php-magic-constants/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 22:06:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=728</guid>
		<description><![CDATA[PHP provides useful magic constants for fetching the current line number (__LINE__), file path (__FILE__), directory path (__DIR__), function name (__FUNCTION__), class name (__CLASS__), method name (__METHOD__) and namespace (__NAMESPACE__). We are not going to cover each one of these &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/20/php-magic-constants/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/20/php-magic-constants/">PHP &#8211; Magic Constants</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>PHP provides useful magic constants for fetching the current line number (__LINE__), file path (__FILE__), directory path (__DIR__), function name (__FUNCTION__), class name (__CLASS__), method name (__METHOD__) and namespace (__NAMESPACE__).</p>
<p>We are not going to cover each one of these in this article, but I will show you a few use cases.</p>
<p>When including other scripts, it is a good idea to utilize the __FILE__ constant (or also __DIR__ , as of PHP 5.3):</p>
<pre class="brush: php; title: ; notranslate">

// this is relative to the loaded script's path
// it may cause problems when running scripts from different directories
require_once('config/database.php');

// this is always relative to this file's path
// no matter where it was included from
require_once(dirname(__FILE__) . '/config/database.php');
</pre>
<p>Using __LINE__ makes debugging easier. You can track down the line numbers:</p>
<pre class="brush: php; title: ; notranslate">

// some code
// ...
my_debug(&quot;some debug message&quot;, __LINE__);
/* prints
Line 4: some debug message
*/

// some more code
// ...
my_debug(&quot;another debug message&quot;, __LINE__);
/* prints
Line 11: another debug message
*/

function my_debug($msg, $line) {
echo &quot;Line $line: $msg\n&quot;;
}
</pre>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2010/11/29/wordpress-easy-debug-mode/" rel="bookmark" class="crp_title">WordPress &#8211; Easy debug mode</a></li><li><a href="http://www.whileifblog.com/2010/07/12/php-optimize-your-jpeg-images-with-imagemagick/" rel="bookmark" class="crp_title">PHP &#8211; Optimize your JPEG images with ImageMagick</a></li><li><a href="http://www.whileifblog.com/2011/01/30/linux-exporting-files-from-git-similar-to-svn-export/" rel="bookmark" class="crp_title">Linux &#8211; Exporting Files From Git (similar to SVN export)</a></li><li><a href="http://www.whileifblog.com/2010/09/04/regex-regular-expression-to-match-a-url/" rel="bookmark" class="crp_title">REGEX &#8211; Regular expression to match a URL</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/20/php-magic-constants/">PHP &#8211; Magic Constants</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/20/php-magic-constants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Memory Usage Information</title>
		<link>http://www.whileifblog.com/2012/02/18/php-memory-usage-information/</link>
		<comments>http://www.whileifblog.com/2012/02/18/php-memory-usage-information/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 16:24:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=725</guid>
		<description><![CDATA[By observing the memory usage of your scripts, you may be able optimize your code better. PHP has a garbage collector and a pretty complex memory manager. The amount of memory being used by your script. can go up and &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/18/php-memory-usage-information/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/18/php-memory-usage-information/">PHP &#8211; Memory Usage Information</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>By observing the memory usage of your scripts, you may be able optimize your code better.</p>
<p>PHP has a garbage collector and a pretty complex memory manager.</p>
<p>The amount of memory being used by your script. can go up and down during the execution of a script. To get the current memory usage, we can use the <strong>memory_get_usage()</strong> function, and to get the highest amount of memory used at any point, we can use the <strong>memory_get_peak_usage()</strong> function.</p>
<pre class="brush: php; title: ; notranslate">
echo &quot;Initial: &quot;.memory_get_usage().&quot; bytes \n&quot;;
/* prints
Initial: 361400 bytes
*/

// let's use up some memory
for ($i = 0; $i &lt; 100000; $i++) {
$array []= md5($i);
}

// let's remove half of the array
for ($i = 0; $i &lt; 100000; $i++) {
unset($array[$i]);
}

echo &quot;Final: &quot;.memory_get_usage().&quot; bytes \n&quot;;
/* prints
Final: 885912 bytes
*/

echo &quot;Peak: &quot;.memory_get_peak_usage().&quot; bytes \n&quot;;
/* prints
Peak: 13687072 bytes
*/
</pre>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2012/02/15/php-functions-with-arbitrary-number-of-arguments/" rel="bookmark" class="crp_title">PHP &#8211; Functions with Arbitrary Number of Arguments</a></li><li><a href="http://www.whileifblog.com/2010/10/05/jquery-preloading-images/" rel="bookmark" class="crp_title">Jquery &#8211; Preloading images</a></li><li><a href="http://www.whileifblog.com/2012/02/20/php-magic-constants/" rel="bookmark" class="crp_title">PHP &#8211; Magic Constants</a></li><li><a href="http://www.whileifblog.com/2011/02/17/wordpress-dynamic-highlight-menu/" rel="bookmark" class="crp_title">WordPress &#8211; Dynamic Highlight Menu</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/18/php-memory-usage-information/">PHP &#8211; Memory Usage Information</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/18/php-memory-usage-information/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Generating Unique ID&#8217;s</title>
		<link>http://www.whileifblog.com/2012/02/16/php-generating-unique-ids/</link>
		<comments>http://www.whileifblog.com/2012/02/16/php-generating-unique-ids/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 20:53:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=723</guid>
		<description><![CDATA[There may be situations where you need to generate a unique string. I have seen many people use the md5() function for this, even though it&#8217;s not exactly meant for this purpose: There is actually a PHP function named uniqid() &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/16/php-generating-unique-ids/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/16/php-generating-unique-ids/">PHP &#8211; Generating Unique ID&#8217;s</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>There may be situations where you need to generate a unique string. I have seen many people use the md5() function for this, even though it&#8217;s not exactly meant for this purpose:</p>
<pre class="brush: php; title: ; notranslate">

// generate unique string
echo md5(time() . mt_rand(1,1000000));
</pre>
<p>There is actually a PHP function named uniqid() that is meant to be used for this.</p>
<pre class="brush: php; title: ; notranslate">
// generate unique string
echo uniqid();
/* prints
4bd64c947233e
*/

// generate another unique string
echo uniqid();
/* prints
4bd67c9412340
*/
</pre>
<p>You may notice that even though the strings are unique, they seem similar for the first several characters. This is because the generated string is related to the server time. This actually has a nice side effect, as every new generated id comes later in alphabetical order, so they can be sorted.<br />
<span id="more-723"></span><br />
To reduce the chances of getting a duplicate, you can pass a prefix, or the second parameter to increase entropy:</p>
<pre class="brush: php; title: ; notranslate">

// with prefix
echo uniqid('foo_');
/* prints
foo_4bd67d6cd8b8f
*/

// with more entropy
echo uniqid('',true);
/* prints
4bd67d6cd8b926.12135106
*/

// both
echo uniqid('bar_',true);
/* prints
bar_4bd67da367b650.43684647
*/
</pre>
<p>This function will generate shorter strings than md5(), which will also save you some space.</p>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2012/02/13/php-random-string-with-numbers-and-letters/" rel="bookmark" class="crp_title">PHP &#8211; Random string with numbers and letters</a></li><li><a href="http://www.whileifblog.com/2012/02/18/php-memory-usage-information/" rel="bookmark" class="crp_title">PHP &#8211; Memory Usage Information</a></li><li><a href="http://www.whileifblog.com/2012/02/15/php-functions-with-arbitrary-number-of-arguments/" rel="bookmark" class="crp_title">PHP &#8211; Functions with Arbitrary Number of Arguments</a></li><li><a href="http://www.whileifblog.com/2011/09/24/php-determining-the-frequency-of-a-string%e2%80%99s-appearance/" rel="bookmark" class="crp_title">PHP &#8211; Determining the Frequency of a String’s Appearance</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/16/php-generating-unique-ids/">PHP &#8211; Generating Unique ID&#8217;s</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/16/php-generating-unique-ids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Functions with Arbitrary Number of Arguments</title>
		<link>http://www.whileifblog.com/2012/02/15/php-functions-with-arbitrary-number-of-arguments/</link>
		<comments>http://www.whileifblog.com/2012/02/15/php-functions-with-arbitrary-number-of-arguments/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 22:28:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=719</guid>
		<description><![CDATA[You may already know that PHP allows you to define functions with optional arguments. But there is also a method for allowing completely arbitrary number of function arguments. First, here is an example with just optional arguments: Now, let’s see &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/15/php-functions-with-arbitrary-number-of-arguments/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/15/php-functions-with-arbitrary-number-of-arguments/">PHP &#8211; Functions with Arbitrary Number of Arguments</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>You may already know that PHP allows you to define functions with optional arguments. But there is also a method for allowing completely arbitrary number of function arguments.</p>
<p>First, here is an example with just optional arguments:</p>
<pre class="brush: php; title: ; notranslate">
// function with 2 optional arguments
function foo($arg1 = '', $arg2 = '') {

echo &quot;arg1: $arg1\n&quot;;
echo &quot;arg2: $arg2\n&quot;;

}
foo('hello','world');
/* prints:
arg1: hello
arg2: world
*/

foo();
/* prints:
arg1:
arg2:
*/
</pre>
<p>Now, let’s see how we can build a function that accepts any number of arguments. This time we are going to utilize <strong>func_get_args(</strong>):</p>
<p><span id="more-719"></span></p>
<pre class="brush: php; title: ; notranslate">
// yes, the argument list can be empty
function foo() {

// returns an array of all passed arguments
$args = func_get_args();

foreach ($args as $k =&gt; $v) {
echo &quot;arg&quot;.($k+1).&quot;: $v\n&quot;;
}

}

foo();
/* prints nothing */

foo('hello');
/* prints
arg1: hello
*/

foo('hello', 'world', 'again');
/* prints
arg1: hello
arg2: world
arg3: again
*/
</pre>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2010/08/19/php-optimization-tricks-i/" rel="bookmark" class="crp_title">PHP &#8211; Optimization Tricks I</a></li><li><a href="http://www.whileifblog.com/2012/02/18/php-memory-usage-information/" rel="bookmark" class="crp_title">PHP &#8211; Memory Usage Information</a></li><li><a href="http://www.whileifblog.com/2010/10/05/jquery-preloading-images/" rel="bookmark" class="crp_title">Jquery &#8211; Preloading images</a></li><li><a href="http://www.whileifblog.com/2010/08/22/php-%e2%80%93-optimization-tricks-iv/" rel="bookmark" class="crp_title">PHP – Optimization Tricks IV</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/15/php-functions-with-arbitrary-number-of-arguments/">PHP &#8211; Functions with Arbitrary Number of Arguments</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/15/php-functions-with-arbitrary-number-of-arguments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Random string with numbers and letters</title>
		<link>http://www.whileifblog.com/2012/02/13/php-random-string-with-numbers-and-letters/</link>
		<comments>http://www.whileifblog.com/2012/02/13/php-random-string-with-numbers-and-letters/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 23:47:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=715</guid>
		<description><![CDATA[I thought that some of you might find it useful to learn how to generate a random string or a random number with PHP. I wrote a quick function to use PHP to generate random. See it below : What &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/13/php-random-string-with-numbers-and-letters/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/13/php-random-string-with-numbers-and-letters/">PHP &#8211; Random string with numbers and letters</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I thought that some of you might find it useful to learn how to generate a random string or a random number with PHP. I wrote a quick function to use PHP to generate random. See it below :</p>
<pre class="brush: php; title: ; notranslate">
function genRandomString() {
$length = 10;
$characters = ’0123456789abcdefghijklmnopqrstuvwxyz’;
$string = ”;

for ($p = 0; $p &lt; $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}

return $string;
}
</pre>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2012/02/16/php-generating-unique-ids/" rel="bookmark" class="crp_title">PHP &#8211; Generating Unique ID&#8217;s</a></li><li><a href="http://www.whileifblog.com/2010/08/19/php-optimization-tricks-i/" rel="bookmark" class="crp_title">PHP &#8211; Optimization Tricks I</a></li><li><a href="http://www.whileifblog.com/2011/09/24/php-determining-the-frequency-of-a-string%e2%80%99s-appearance/" rel="bookmark" class="crp_title">PHP &#8211; Determining the Frequency of a String’s Appearance</a></li><li><a href="http://www.whileifblog.com/2010/09/03/regex-validate-email-address/" rel="bookmark" class="crp_title">REGEX &#8211; Validate Email address</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/13/php-random-string-with-numbers-and-letters/">PHP &#8211; Random string with numbers and letters</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/13/php-random-string-with-numbers-and-letters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery &#8211; Accessing Native Properties and Methods</title>
		<link>http://www.whileifblog.com/2012/02/11/jquery-accessing-native-properties-and-methods/</link>
		<comments>http://www.whileifblog.com/2012/02/11/jquery-accessing-native-properties-and-methods/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 18:40:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=712</guid>
		<description><![CDATA[So you&#8217;ve learned a bit of JavaScript, and have learned that, for instance, on anchor tags, you can access attribute values directly: The only problem is that this doesn&#8217;t seem to work when you reference the DOM elements with jQuery, &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/11/jquery-accessing-native-properties-and-methods/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/11/jquery-accessing-native-properties-and-methods/">JQuery &#8211; Accessing Native Properties and Methods</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve learned a bit of JavaScript, and have learned that, for instance, on anchor tags, you can access attribute values directly:</p>
<pre class="brush: jscript; title: ; notranslate">
var anchor = document.getElementById('someAnchor');
//anchor.id
// anchor.href
// anchor.title
// .etc
</pre>
<p>The only problem is that this doesn&#8217;t seem to work when you reference the DOM elements with jQuery, right? Well of course not.</p>
<pre class="brush: jscript; title: ; notranslate">

// Fails
var id = $('#someAnchor').id;
</pre>
<p>So, should you need to access the href attribute (or any other native property or method for that matter), you have a handful of options.</p>
<pre class="brush: jscript; title: ; notranslate">
// OPTION 1 - Use jQuery
var id = $('#someAnchor').attr('id');

// OPTION 2 - Access the DOM element
var id = $('#someAnchor')[0].id;

// OPTION 3 - Use jQuery's get method
var id = $('#someAnchor').get(0).id;

// OPTION 3b - Don't pass an index to get
anchorsArray = $('.someAnchors').get();
var thirdId = anchorsArray[2].id;
</pre>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2010/07/18/jquery-manipulating-dom-examples/" rel="bookmark" class="crp_title">JQuery &#8211; Manipulating DOM examples</a></li><li><a href="http://www.whileifblog.com/2010/11/11/jquery-access-iframe-elements/" rel="bookmark" class="crp_title">Jquery &#8211; Access iFrame Elements</a></li><li><a href="http://www.whileifblog.com/2012/02/09/jquery-passing-an-attribute-object/" rel="bookmark" class="crp_title">JQuery &#8211; Passing an Attribute Object</a></li><li><a href="http://www.whileifblog.com/2012/02/07/jquery-keep-your-code-safe/" rel="bookmark" class="crp_title">JQuery &#8211; Keep your Code Safe</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/11/jquery-accessing-native-properties-and-methods/">JQuery &#8211; Accessing Native Properties and Methods</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/11/jquery-accessing-native-properties-and-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery  &#8211; Detect AJAX Requests with PHP</title>
		<link>http://www.whileifblog.com/2012/02/10/jquery-detect-ajax-requests-with-php/</link>
		<comments>http://www.whileifblog.com/2012/02/10/jquery-detect-ajax-requests-with-php/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 23:20:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=709</guid>
		<description><![CDATA[Certainly, for the huge majority of our projects, we can&#8217;t only rely on JavaScript for things like validation, or AJAX requests. What happens when JavaScript is turned off? For this very reason, a common technique is to detect whether an &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/10/jquery-detect-ajax-requests-with-php/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/10/jquery-detect-ajax-requests-with-php/">JQuery  &#8211; Detect AJAX Requests with PHP</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Certainly, for the huge majority of our projects, we can&#8217;t only rely on JavaScript for things like validation, or AJAX requests. What happens when JavaScript is turned off? For this very reason, a common technique is to detect whether an AJAX request has been made with your server-side language of choice.</p>
<p>jQuery makes this ridiculously simple, by setting a header from within the $.ajax method.</p>
<pre class="brush: jscript; title: ; notranslate">
 // Set header so the called script knows that it's an XMLHttpRequest
 // Only send the header if it's not a remote XHR
 if ( !remote ) {
 xhr.setRequestHeader(&quot;X-Requested-With&quot;, &quot;XMLHttpRequest&quot;);
 }
 </pre>
<p>With this header set, we can now use PHP (or any other language) to check for this header, and proceed accordingly. For this, we check the value of $_SERVER['HTTP_X_REQUESTED_WITH'].</p>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2011/09/12/javascript-function-to-manage-function-timeout/" rel="bookmark" class="crp_title">Javascript &#8211; function to manage function timeout</a></li><li><a href="http://www.whileifblog.com/2011/09/26/htaccess-improve-site-transfer-speed-by-enabling-file-caching/" rel="bookmark" class="crp_title">Htaccess &#8211; Improve Site Transfer Speed by Enabling File Caching</a></li><li><a href="http://www.whileifblog.com/2010/09/28/jquery-lazy-load-content-for-speed-and-seo-benefits/" rel="bookmark" class="crp_title">Jquery &#8211; Lazy load content for speed and SEO benefits</a></li><li><a href="http://www.whileifblog.com/2011/09/12/jquery-add-tabs-without-a-plugin/" rel="bookmark" class="crp_title">Jquery &#8211; Add Tabs without a Plugin</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/10/jquery-detect-ajax-requests-with-php/">JQuery  &#8211; Detect AJAX Requests with PHP</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/10/jquery-detect-ajax-requests-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery &#8211; Passing an Attribute Object</title>
		<link>http://www.whileifblog.com/2012/02/09/jquery-passing-an-attribute-object/</link>
		<comments>http://www.whileifblog.com/2012/02/09/jquery-passing-an-attribute-object/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 22:16:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=707</guid>
		<description><![CDATA[As of jQuery 1.4, we can now pass an object as the second parameter of the jQuery function. This is helpful when we need to insert new elements into the DOM. For example: Before After Not only does this save &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/09/jquery-passing-an-attribute-object/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/09/jquery-passing-an-attribute-object/">JQuery &#8211; Passing an Attribute Object</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As of jQuery 1.4, we can now pass an object as the second parameter of the jQuery function. This is helpful when we need to insert new elements into the DOM. For example:</p>
<p><strong>Before</strong></p>
<pre class="brush: jscript; title: ; notranslate">
    $('')
      .attr({
        id : 'someId',
        className : 'someClass',
        href : 'somePath.html'
      });
</pre>
<p><strong>After</strong></p>
<pre class="brush: jscript; title: ; notranslate">
    $('', {
        id : 'someId',
        className : 'someClass',
        href : 'somePath.html'
    });
</pre>
<p>Not only does this save a few characters, but it also makes for cleaner code. In addition to element attributes, we can even pass jQuery specific attributes and events, like click or text.</p>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2012/02/11/jquery-accessing-native-properties-and-methods/" rel="bookmark" class="crp_title">JQuery &#8211; Accessing Native Properties and Methods</a></li><li><a href="http://www.whileifblog.com/2012/02/07/jquery-keep-your-code-safe/" rel="bookmark" class="crp_title">JQuery &#8211; Keep your Code Safe</a></li><li><a href="http://www.whileifblog.com/2012/02/08/jquery-a-single-hover-function/" rel="bookmark" class="crp_title">JQuery &#8211; A Single Hover Function</a></li><li><a href="http://www.whileifblog.com/2010/07/18/jquery-manipulating-dom-examples/" rel="bookmark" class="crp_title">JQuery &#8211; Manipulating DOM examples</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/09/jquery-passing-an-attribute-object/">JQuery &#8211; Passing an Attribute Object</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/09/jquery-passing-an-attribute-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery &#8211; A Single Hover Function</title>
		<link>http://www.whileifblog.com/2012/02/08/jquery-a-single-hover-function/</link>
		<comments>http://www.whileifblog.com/2012/02/08/jquery-a-single-hover-function/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 20:29:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.whileifblog.com/?p=703</guid>
		<description><![CDATA[As of jQuery 1.4, we can now pass only a single function to the hover method. Before, both the in and out methods were required. Before Now Note that this isn&#8217;t an old vs. new deal. Many times, you&#8217;ll still &#8230;<p class="read-more"><a href="http://www.whileifblog.com/2012/02/08/jquery-a-single-hover-function/">Read more &#187;</a></p><p><a href="http://www.whileifblog.com/2012/02/08/jquery-a-single-hover-function/">JQuery &#8211; A Single Hover Function</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As of <strong>jQuery 1.4</strong>, we can now pass only a single function to the hover method. Before, both the in and out methods were required.</p>
<p><strong>Before</strong></p>
<pre class="brush: jscript; title: ; notranslate">
$('#someElement').hover(function() {
// mouseover
}, function() {
// mouseout
});
</pre>
<p><strong>Now</strong></p>
<pre class="brush: jscript; title: ; notranslate">
 $('#someElement').hover(function() {
 // the toggle() method can be used here, if applicable
 });
 </pre>
<p>Note that this isn&#8217;t an old vs. new deal. Many times, you&#8217;ll still need to pass two functions to hover, and that&#8217;s perfectly acceptable. However, if you only need to toggle some element (or something like that), passing a single anonymous function will save a handful of characters or so!</p>
<div id="crp_related"><h2 class="title" style="padding-top:15px">What others are reading:</h2><ul><li><a href="http://www.whileifblog.com/2012/02/07/jquery-keep-your-code-safe/" rel="bookmark" class="crp_title">JQuery &#8211; Keep your Code Safe</a></li><li><a href="http://www.whileifblog.com/2012/02/09/jquery-passing-an-attribute-object/" rel="bookmark" class="crp_title">JQuery &#8211; Passing an Attribute Object</a></li><li><a href="http://www.whileifblog.com/2012/02/11/jquery-accessing-native-properties-and-methods/" rel="bookmark" class="crp_title">JQuery &#8211; Accessing Native Properties and Methods</a></li><li><a href="http://www.whileifblog.com/2010/07/18/jquery-manipulating-dom-examples/" rel="bookmark" class="crp_title">JQuery &#8211; Manipulating DOM examples</a></li></ul></div><p><a href="http://www.whileifblog.com/2012/02/08/jquery-a-single-hover-function/">JQuery &#8211; A Single Hover Function</a> is a post from: <a href="http://www.whileifblog.com">WhileIf Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.whileifblog.com/2012/02/08/jquery-a-single-hover-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

