<?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>Experts Guide</title>
	<atom:link href="http://www.expertsguide.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.expertsguide.info</link>
	<description>Tips and Tricks on Web and Technology</description>
	<lastBuildDate>Thu, 16 Feb 2012 18:05:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CSS Selectors</title>
		<link>http://www.expertsguide.info/2012/02/css-selectors/</link>
		<comments>http://www.expertsguide.info/2012/02/css-selectors/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 18:00:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=440</guid>
		<description><![CDATA[<p>CSS Selectors are the most handy way to apply styles to select HTML elements. CSS Selectors are widely used in jQuery and HTML DOM Parsers etc.</p>

a.[href*="jpg"] {
color : green;
}
<p>This will apply the style to all anchor tags which have their href tag linking to jpg images.</p>

a.[href*="jpg"][id="nav"] {
color : green;
}
<p>This will apply the style to all anchor <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2012/02/css-selectors/">CSS Selectors</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/' rel='bookmark' title='Permanent Link: Use .htaccess to rewrite/redirect requests'>Use .htaccess to rewrite/redirect requests</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>CSS Selectors are the most handy way to apply styles to select HTML elements. CSS Selectors are widely used in jQuery and HTML DOM Parsers etc.</p>
<pre class="brush:css">
a.[href*="jpg"] {
color : green;
}</pre>
<p>This will apply the style to all anchor tags which have their href tag linking to jpg images.</p>
<pre class="brush:css">
a.[href*="jpg"][id="nav"] {
color : green;
}</pre>
<p>This will apply the style to all anchor tags which have their href tag linking to jpg images AND (satisfy both requirements) which have id as &#8220;nav&#8221;.</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/' rel='bookmark' title='Permanent Link: Use .htaccess to rewrite/redirect requests'>Use .htaccess to rewrite/redirect requests</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2012/02/css-selectors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS margin style property not working</title>
		<link>http://www.expertsguide.info/2011/11/css-margin-style-property-not-working/</link>
		<comments>http://www.expertsguide.info/2011/11/css-margin-style-property-not-working/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 10:03:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=431</guid>
		<description><![CDATA[<p>There&#8217;s a weird characteristic of margin style property. Instead of adding two margins together, a web browser applies the larger of the two margins. This is called colliding margins.</p>
<p>For example, if there an unordered list tag above a paragraph tag. The list tag is assigned with the bottom margin of 20 pixels and the paragraph is <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2011/11/css-margin-style-property-not-working/">CSS margin style property not working</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/css-font-size-property-not-working-in-internet-explorer/' rel='bookmark' title='Permanent Link: CSS font-size property not working in Internet Explorer'>CSS font-size property not working in Internet Explorer</a></li>
<li><a href='http://www.expertsguide.info/2010/09/how-to-know-memory-used-by-current-running-tasks-on-windows/' rel='bookmark' title='Permanent Link: How to know memory used by current running tasks on Windows'>How to know memory used by current running tasks on Windows</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a weird characteristic of margin style property. Instead of adding two margins together, a web browser applies the larger of the two margins. This is called <strong>colliding margins</strong>.</p>
<p>For example, if there an unordered list tag above a paragraph tag. The list tag is assigned with the bottom margin of 20 pixels and the paragraph is assigned a value of  top margin as 20 pixels.</p>
<pre class="brush:css">&lt;ul style="margin-bottom: 20px;"&gt;&lt;li&gt;&lt;li&gt;&lt;/ul&gt;

&lt;p style="margin-bottom: 10px;"&gt;&lt;/p&gt;</pre>
<p>Then, a general perception would be that the browser adds them up and puts 30 pixels of white space between the paragraph and the list. But this doesn&#8217;t happen. The browser applies the larger (20px here) of the two. And you see only 20px wide white space.</p>
<p>Workaround: Use padding on one tag along with margin on another. </p>
<p>Note: left, right margins, margins between flating elements and margins between absolutely/relatively positioned elements, don&#8217;t behave this way (colliding).</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/css-font-size-property-not-working-in-internet-explorer/' rel='bookmark' title='Permanent Link: CSS font-size property not working in Internet Explorer'>CSS font-size property not working in Internet Explorer</a></li>
<li><a href='http://www.expertsguide.info/2010/09/how-to-know-memory-used-by-current-running-tasks-on-windows/' rel='bookmark' title='Permanent Link: How to know memory used by current running tasks on Windows'>How to know memory used by current running tasks on Windows</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2011/11/css-margin-style-property-not-working/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inner Join example in MySQL</title>
		<link>http://www.expertsguide.info/2011/10/inner-join-example-in-mysql/</link>
		<comments>http://www.expertsguide.info/2011/10/inner-join-example-in-mysql/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 10:57:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=414</guid>
		<description><![CDATA[<p>Suppose we have two different tables in Database, one having product ID and product name and the other having product ID and price, as shown below,</p>
<p>Table_1</p>



product_id

product_name


1

Car


2

Truck


3

Scooter


4

Bicycle



<p>
Table_2</p>



product_id

product_price


1

50000


2

60000


3

5000


4

1000



<p>
then to show the product names with their price, we can write an SQL statement (Inner Join) like this,</p>
SELECT a.product_name, b.product_price FROM Table_1 a, Table_2 WHERE a.product_id=b.product_id;
<p>This would give you the <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2011/10/inner-join-example-in-mysql/">Inner Join example in MySQL</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/09/common-mistakes-and-points-to-remember-in-mysql/' rel='bookmark' title='Permanent Link: Common mistakes and points to remember in MySQL'>Common mistakes and points to remember in MySQL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Suppose we have two different tables in Database, one having product ID and product name and the other having product ID and price, as shown below,</p>
<p>Table_1</p>
<table>
<tbody>
<tr>
<td>product_id</td>
<td></td>
<td>product_name</td>
</tr>
<tr>
<td>1</td>
<td></td>
<td>Car</td>
</tr>
<tr>
<td>2</td>
<td></td>
<td>Truck</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>Scooter</td>
</tr>
<tr>
<td>4</td>
<td></td>
<td>Bicycle</td>
</tr>
</tbody>
</table>
<p>
Table_2</p>
<table>
<tbody>
<tr>
<td>product_id</td>
<td></td>
<td>product_price</td>
</tr>
<tr>
<td>1</td>
<td></td>
<td>50000</td>
</tr>
<tr>
<td>2</td>
<td></td>
<td>60000</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>5000</td>
</tr>
<tr>
<td>4</td>
<td></td>
<td>1000</td>
</tr>
</tbody>
</table>
<p>
then to show the product names with their price, we can write an SQL statement (Inner Join) like this,</p>
<pre class="brush:sql">SELECT a.product_name, b.product_price FROM Table_1 a, Table_2 WHERE a.product_id=b.product_id;</pre>
<p>This would give you the result as,</p>
<table>
<tbody>
<tr>
<td>a.product_name</td>
<td></td>
<td>b.product_price</td>
</tr>
<tr>
<td>Car</td>
<td></td>
<td>50000</td>
</tr>
<tr>
<td>Truck</td>
<td></td>
<td>60000</td>
</tr>
<tr>
<td>Scooter</td>
<td></td>
<td>5000</td>
</tr>
<tr>
<td>Bicycle</td>
<td></td>
<td>1000</td>
</tr>
</tbody>
</table>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/09/common-mistakes-and-points-to-remember-in-mysql/' rel='bookmark' title='Permanent Link: Common mistakes and points to remember in MySQL'>Common mistakes and points to remember in MySQL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2011/10/inner-join-example-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to find all occurrences of a string in another string using Perl</title>
		<link>http://www.expertsguide.info/2011/09/how_to_find_all_occurrences_of_a_string_in_another_string_using_perl/</link>
		<comments>http://www.expertsguide.info/2011/09/how_to_find_all_occurrences_of_a_string_in_another_string_using_perl/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 08:07:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=409</guid>
		<description><![CDATA[<p>How to find all occurrences of a string in another string using Perl?</p>
#!/usr/bin/perl
use strict;
use warnings;

my $string = 'needle in the haystack. needle again. needle';
my $find_me = 'needle';
my $offset = 0;
my $result = index($string, $find_me, $offset);

while ($result != -1) {
   print "Found $find_me at $result\n";
   $offset = $result + 1;
   $result <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2011/09/how_to_find_all_occurrences_of_a_string_in_another_string_using_perl/">How to find all occurrences of a string in another string using Perl</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2011/07/greedy-search-in-perl-regular-expressions/' rel='bookmark' title='Permanent Link: Greedy Search in Perl Regular Expressions'>Greedy Search in Perl Regular Expressions</a></li>
<li><a href='http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/' rel='bookmark' title='Permanent Link: Alter Regular Expression Match Position in Perl'>Alter Regular Expression Match Position in Perl</a></li>
<li><a href='http://www.expertsguide.info/2010/09/how-to-know-if-document-exists-on-a-url-in-perl/' rel='bookmark' title='Permanent Link: How to know if document exists on a URL in perl'>How to know if document exists on a URL in perl</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How to find all occurrences of a string in another string using Perl?</p>
<pre class="brush:perl">#!/usr/bin/perl
use strict;
use warnings;

my $string = 'needle in the haystack. needle again. needle';
my $find_me = 'needle';
my $offset = 0;
my $result = index($string, $find_me, $offset);

while ($result != -1) {
   print "Found $find_me at $result\n";
   $offset = $result + 1;
   $result = index($string, $find_me, $offset);
}</pre>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2011/07/greedy-search-in-perl-regular-expressions/' rel='bookmark' title='Permanent Link: Greedy Search in Perl Regular Expressions'>Greedy Search in Perl Regular Expressions</a></li>
<li><a href='http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/' rel='bookmark' title='Permanent Link: Alter Regular Expression Match Position in Perl'>Alter Regular Expression Match Position in Perl</a></li>
<li><a href='http://www.expertsguide.info/2010/09/how-to-know-if-document-exists-on-a-url-in-perl/' rel='bookmark' title='Permanent Link: How to know if document exists on a URL in perl'>How to know if document exists on a URL in perl</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2011/09/how_to_find_all_occurrences_of_a_string_in_another_string_using_perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compare Bing and Google results on same page</title>
		<link>http://www.expertsguide.info/2011/08/compare-bing-and-google-results-on-same-page/</link>
		<comments>http://www.expertsguide.info/2011/08/compare-bing-and-google-results-on-same-page/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 18:30:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=400</guid>
		<description><![CDATA[<p>Sometimes we want to compare the search results of the two most popular search engines, one besides the other. It is difficult to do so in two different instances of browser and then compare. Google has provided this facility on a single page itself.</p>
<p>Try www.bing-vs-google.com</p>
<p class="wp-caption-text">bing-vs-google</p>
<p>Interesting?  </p>


<p>Related posts:how to set or change a default printer <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2011/08/compare-bing-and-google-results-on-same-page/">Compare Bing and Google results on same page</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/' rel='bookmark' title='Permanent Link: how to set or change a default printer on windows?'>how to set or change a default printer on windows?</a></li>
<li><a href='http://www.expertsguide.info/2010/09/how-to-compare-the-execution-time-of-php-code-blocks/' rel='bookmark' title='Permanent Link: How to compare the execution time of PHP code blocks'>How to compare the execution time of PHP code blocks</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Sometimes we want to compare the search results of the two most popular search engines, one besides the other. It is difficult to do so in two different instances of browser and then compare. Google has provided this facility on a single page itself.</p>
<p>Try <strong>www.bing-vs-google.com</strong></p>
<div id="attachment_401" class="wp-caption aligncenter" style="width: 760px"><a href="http://www.expertsguide.info/wp-content/uploads/2011/08/bing-vs-google.gif"><img class="size-medium wp-image-401    " title="bing-vs-google" src="http://www.expertsguide.info/wp-content/uploads/2011/08/bing-vs-google-300x170.gif" alt="bing-vs-google" width="750" height="470" /></a><p class="wp-caption-text">bing-vs-google</p></div>
<p>Interesting? <img src='http://www.expertsguide.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/' rel='bookmark' title='Permanent Link: how to set or change a default printer on windows?'>how to set or change a default printer on windows?</a></li>
<li><a href='http://www.expertsguide.info/2010/09/how-to-compare-the-execution-time-of-php-code-blocks/' rel='bookmark' title='Permanent Link: How to compare the execution time of PHP code blocks'>How to compare the execution time of PHP code blocks</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2011/08/compare-bing-and-google-results-on-same-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Greedy Search in Perl Regular Expressions</title>
		<link>http://www.expertsguide.info/2011/07/greedy-search-in-perl-regular-expressions/</link>
		<comments>http://www.expertsguide.info/2011/07/greedy-search-in-perl-regular-expressions/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 12:18:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=394</guid>
		<description><![CDATA[<p>You might have come across the problem of .* capturing all the pattern it matches in the string, while you wanted only a part of it. E.g.,</p>
$var = 'some_url?id=1&#38;number=2&#38;name=Peter&#38;address=someaddress';
<p>In the above string if you only want to capture the value of &#8220;id&#8221; (i.e. 1) and you use this regex</p>
$var =~ /\?(.*)=(.*)\&#38;/ ;
<p>it will not work as expected. $1 would have <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2011/07/greedy-search-in-perl-regular-expressions/">Greedy Search in Perl Regular Expressions</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/' rel='bookmark' title='Permanent Link: Alter Regular Expression Match Position in Perl'>Alter Regular Expression Match Position in Perl</a></li>
<li><a href='http://www.expertsguide.info/2010/09/how-to-know-if-document-exists-on-a-url-in-perl/' rel='bookmark' title='Permanent Link: How to know if document exists on a URL in perl'>How to know if document exists on a URL in perl</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/' rel='bookmark' title='Permanent Link: How to get elements from one array but not in another array'>How to get elements from one array but not in another array</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>You might have come across the problem of .* capturing all the pattern it matches in the string, while you wanted only a part of it. E.g.,</p>
<pre class="brush:perl">$var = 'some_url?id=1&amp;number=2&amp;name=Peter&amp;address=someaddress';</pre>
<p>In the above string if you only want to capture the value of &#8220;id&#8221; (i.e. 1) and you use this regex</p>
<pre class="brush:perl">$var =~ /\?(.*)=(.*)\&amp;/ ;</pre>
<p>it will not work as expected. $1 would have this</p>
<pre class="brush:perl">id=1&amp;number=2&amp;name</pre>
<p>(.*) tries to capture as much matching content as possible. In other words it is greedy (wants to have more and more). But of-course only the content which matches the pattern.</p>
<p>If you want to capture id=1 only in $1 and $2 respectively you have to refrain the greed of regex by using ? (question mark) like this,</p>
<pre class="brush:perl">$var =~ /\?(.*?)=(.*?)\&amp;/ ;
print "$1 and $2\n";</pre>
<p>it would print,</p>
<pre class="brush:perl">id and 1</pre>
<p>You can use (.+) in place of (.*) to make sure that it matches only when some character there for sure, on eor more times.</p>
<pre class="brush:perl">$var =~ /\?(.+?)=(.+?)\&amp;/ ;</pre>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/' rel='bookmark' title='Permanent Link: Alter Regular Expression Match Position in Perl'>Alter Regular Expression Match Position in Perl</a></li>
<li><a href='http://www.expertsguide.info/2010/09/how-to-know-if-document-exists-on-a-url-in-perl/' rel='bookmark' title='Permanent Link: How to know if document exists on a URL in perl'>How to know if document exists on a URL in perl</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/' rel='bookmark' title='Permanent Link: How to get elements from one array but not in another array'>How to get elements from one array but not in another array</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2011/07/greedy-search-in-perl-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>send mail using mail command in UNIX</title>
		<link>http://www.expertsguide.info/2011/06/send-mail-using-mail-command-in-unix/</link>
		<comments>http://www.expertsguide.info/2011/06/send-mail-using-mail-command-in-unix/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 14:13:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=388</guid>
		<description><![CDATA[<p>Sometimes we need to send e-mails from UNIX command-line itself. Sometimes we need to write a small script to do so. Here&#8217;s what we need to do for such tasks.</p>
<p>We can send mail in UNIX using &#8220;mail&#8221; command. Syntax is as follows,</p>
mail -s "Subject" -c "any_cc_email_id" -b "any_bc_email_id" "comma_separated_To_email_id"
<p>But the above syntax is used when we <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2011/06/send-mail-using-mail-command-in-unix/">send mail using mail command in UNIX</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/send-mail-when-googlebot-crawls-a-webpage/' rel='bookmark' title='Permanent Link: How to send mail when Googlebot crawls a webpage of your website'>How to send mail when Googlebot crawls a webpage of your website</a></li>
<li><a href='http://www.expertsguide.info/2010/07/find-files-having-some-pattern-using-grep-in-unix/' rel='bookmark' title='Permanent Link: Find all files having some pattern using grep in UNIX'>Find all files having some pattern using grep in UNIX</a></li>
<li><a href='http://www.expertsguide.info/2010/08/http-authentication-in-url-not-working-in-ie/' rel='bookmark' title='Permanent Link: HTTP Authentication in URL not working in IE'>HTTP Authentication in URL not working in IE</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need to send e-mails from UNIX command-line itself. Sometimes we need to write a small script to do so. Here&#8217;s what we need to do for such tasks.</p>
<p>We can send mail in UNIX using &#8220;mail&#8221; command. Syntax is as follows,</p>
<pre class="brush:bash">mail -s "Subject" -c "any_cc_email_id" -b "any_bc_email_id" "comma_separated_To_email_id"</pre>
<p>But the above syntax is used when we are typing the message body at command-line itself.</p>
<p>If we want to use the body text from some variable or from some pipe (|) we need to use following syntax,</p>
<pre class="brush:bash">echo $message | mail -s "Subject" -c "any_cc_email_id" -b "any_bc_email_id" "comma_separated_To_email_id"</pre>
<p>e.g.,</p>
<pre class="brush:bash">echo "Hi Friend, this is mail body" | mail -s "Hi Friend" "info@expertsguide.info,abcd@gmail.com"</pre>
<p>If we want to get the message body from a file rather than from a variable, we need to following syntax</p>
<pre class="brush:bash">mail -s "Subject" -c "any_cc_email_id" -b "any_bc_email_id" "comma_separated_To_email_id" &lt; file.txt</pre>
<p>e.g.,</p>
<pre class="brush:bash">mail -s "Hi Friend" "info@expertsguide.info,abcd@gmail.com" &lt; myfile.log</pre>
<p>Lot of programmers ask about how to send this mail to multiple users. Please note that they need to put comma separated email ids and not space separated ones in the above syntax (as I have already shown).</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/send-mail-when-googlebot-crawls-a-webpage/' rel='bookmark' title='Permanent Link: How to send mail when Googlebot crawls a webpage of your website'>How to send mail when Googlebot crawls a webpage of your website</a></li>
<li><a href='http://www.expertsguide.info/2010/07/find-files-having-some-pattern-using-grep-in-unix/' rel='bookmark' title='Permanent Link: Find all files having some pattern using grep in UNIX'>Find all files having some pattern using grep in UNIX</a></li>
<li><a href='http://www.expertsguide.info/2010/08/http-authentication-in-url-not-working-in-ie/' rel='bookmark' title='Permanent Link: HTTP Authentication in URL not working in IE'>HTTP Authentication in URL not working in IE</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2011/06/send-mail-using-mail-command-in-unix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Red ants in laptop</title>
		<link>http://www.expertsguide.info/2010/11/red-ants-in-laptop/</link>
		<comments>http://www.expertsguide.info/2010/11/red-ants-in-laptop/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 02:57:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=385</guid>
		<description><![CDATA[<p>For some of us, red ants  or fire ants in laptop is not an unusual thing to see. One might want to know, is it of any harm or can be ignored? Do they eat up the electronic parts, insulation etc. or do they short the electronic circuit out?</p>
<p>The answer is that they are definitely harmful <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/11/red-ants-in-laptop/">Red ants in laptop</a></span>]]></description>
			<content:encoded><![CDATA[<p>For some of us, red ants  or fire ants in laptop is not an unusual thing to see. One might want to know, is it of any harm or can be ignored? Do they eat up the electronic parts, insulation etc. or do they short the electronic circuit out?</p>
<p>The answer is that they are definitely harmful but not sure what exactly they do inside. Reason, why red ants get attracted to the laptops or other electronic items, is still unknown.</p>
<p>Hence, do not ignore the red ants if they have sneaked into your laptop. Get rid of them without wasting a minute.<br />
Else, you might have to replace the hard disk or keyboard or may be the whole motherboard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/11/red-ants-in-laptop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Difference between Optical Mouse and Laser Mouse</title>
		<link>http://www.expertsguide.info/2010/10/difference-between-optical-mouse-and-laser-mouse/</link>
		<comments>http://www.expertsguide.info/2010/10/difference-between-optical-mouse-and-laser-mouse/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 08:07:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=381</guid>
		<description><![CDATA[<p>Difference between an Optical Mouse and a Laser Mouse</p>
<p>Optical mouse and laser mouse are different varieties of digital mice which have overwhelmed ball rollers ones.</p>
<p>Laser mouse is one step ahead of optical mouse. Laser ones are more precise than optical ones and can respond to very little movements also (extra sensitive). This difference is because of <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/10/difference-between-optical-mouse-and-laser-mouse/">Difference between Optical Mouse and Laser Mouse</a></span>]]></description>
			<content:encoded><![CDATA[<p><strong>Difference between an Optical Mouse and a Laser Mouse</strong></p>
<p>Optical mouse and laser mouse are different varieties of digital mice which have overwhelmed ball rollers ones.</p>
<p>Laser mouse is one step ahead of optical mouse. Laser ones are more precise than optical ones and can respond to very little movements also (extra sensitive). This difference is because of the type of light used. An optical mouse uses an LED light while a laser mouse contains a small laser and hence is a bit expensive, comparatively. An LED light in simple mouse is a visible red light while a laser light might not be visible.</p>
<p><strong>Rating: </strong></p>
<p>Optical mouse -  400 to 800 dpi (dots per inch)</p>
<p>Laser mouse &#8211; 2000 dpi or more.</p>
<p><strong>Who should buy:</strong></p>
<p>Good for Gamers and professional graphic designers.</p>
<p>Not much helpful for typical computer users.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/10/difference-between-optical-mouse-and-laser-mouse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to know if document exists on a URL in perl</title>
		<link>http://www.expertsguide.info/2010/09/how-to-know-if-document-exists-on-a-url-in-perl/</link>
		<comments>http://www.expertsguide.info/2010/09/how-to-know-if-document-exists-on-a-url-in-perl/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 12:33:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=378</guid>
		<description><![CDATA[<p>Pinging a server doesn&#8217;t not actually tell if the   web server is up and available or not.  To check if a server is available and responding or a document exists on a URL, use this,</p>
use LWP::Simple;
$URL='http://www.expertsguide.info/';
if (head($URL))
{
   print '$URL exists' ;
}
else
{
   print 'URL does not contain anything';
}
<p>head() function returns much more information <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/09/how-to-know-if-document-exists-on-a-url-in-perl/">How to know if document exists on a URL in perl</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/' rel='bookmark' title='Permanent Link: Alter Regular Expression Match Position in Perl'>Alter Regular Expression Match Position in Perl</a></li>
<li><a href='http://www.expertsguide.info/2010/08/new-text-document-on-right-click-menu-missing/' rel='bookmark' title='Permanent Link: New Text Document on right click menu missing'>New Text Document on right click menu missing</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/' rel='bookmark' title='Permanent Link: How to access elements having some Class using Javascript?'>How to access elements having some Class using Javascript?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Pinging a server doesn&#8217;t not actually tell if the   web server is up and available or not.  To check if a server is available and responding or a document exists on a URL, use this,</p>
<pre class="brush:pl">use LWP::Simple;
$URL='http://www.expertsguide.info/';
if (head($URL))
{
   print '$URL exists' ;
}
else
{
   print 'URL does not contain anything';
}</pre>
<p>head() function returns much more information eg,  Content-type, document length, last modified  time, expiry date and server name. Capture that using,</p>
<pre class="brush:pl">my @headers = head $URL;
print join "\n", @headers;</pre>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/' rel='bookmark' title='Permanent Link: Alter Regular Expression Match Position in Perl'>Alter Regular Expression Match Position in Perl</a></li>
<li><a href='http://www.expertsguide.info/2010/08/new-text-document-on-right-click-menu-missing/' rel='bookmark' title='Permanent Link: New Text Document on right click menu missing'>New Text Document on right click menu missing</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/' rel='bookmark' title='Permanent Link: How to access elements having some Class using Javascript?'>How to access elements having some Class using Javascript?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/09/how-to-know-if-document-exists-on-a-url-in-perl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to know memory used by current running tasks on Windows</title>
		<link>http://www.expertsguide.info/2010/09/how-to-know-memory-used-by-current-running-tasks-on-windows/</link>
		<comments>http://www.expertsguide.info/2010/09/how-to-know-memory-used-by-current-running-tasks-on-windows/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 11:47:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=374</guid>
		<description><![CDATA[<p>Just like &#8220;ps -ef&#8221; on UNIX there&#8217;s a handy command (&#8220;tasklist&#8221;) on windows which shows all the tasks (processes) running currently and memory used by them.</p>
<p>If you open the command prompt on windows (Start-&#62;Run-&#62;cmd  and Press Enter), it opens a command prompt. Type &#8220;tasklist&#8221; and press enter. It gives a long table with 5 columns (Image <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/09/how-to-know-memory-used-by-current-running-tasks-on-windows/">How to know memory used by current running tasks on Windows</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/' rel='bookmark' title='Permanent Link: how to set or change a default printer on windows?'>how to set or change a default printer on windows?</a></li>
<li><a href='http://www.expertsguide.info/2010/09/common-mistakes-and-points-to-remember-in-mysql/' rel='bookmark' title='Permanent Link: Common mistakes and points to remember in MySQL'>Common mistakes and points to remember in MySQL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Just like &#8220;ps -ef&#8221; on UNIX there&#8217;s a handy command (&#8220;tasklist&#8221;) on windows which shows all the tasks (processes) running currently and memory used by them.</p>
<p>If you open the command prompt on windows (Start-&gt;Run-&gt;cmd  and Press Enter), it opens a command prompt. Type &#8220;tasklist&#8221; and press enter. It gives a long table with 5 columns (Image Name, PID,  Session Name, Session #, Mem Usage)</p>
<p>First column &#8220;Image Name&#8221; shows the executable running corresponding to a task or process, e.g., for Mozilla Firefox it should be &#8220;firefox.exe&#8221;, second column shows it&#8217;s process Id (PID) and the last one memory used (Mem Usage)</p>
<p>If we want to get the result only for processes using memory larger than 50000 KB we can use this command,</p>
<pre>tasklist /FI "MEMUSAGE gt 50000" /FO TABLE</pre>
<p>where,<br />
/FI denotes the field-name input identifier (any one of the five fields)<br />
/FO denotes Field output format (this can be either TABLE,LIST or CSV)</p>
<p>Similary,<br />
If we want to get the memory usage of a process with it&#8217;s id use this</p>
<pre>tasklist /FI "PID eq 4568" /FO LIST</pre>
<p>This can be used in various scripts on windows or by programming languages like Perl, PHP, C, etc. running on windows.</p>
<p>To get the syntax and help text use this,</p>
<pre>tasklist /?</pre>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/' rel='bookmark' title='Permanent Link: how to set or change a default printer on windows?'>how to set or change a default printer on windows?</a></li>
<li><a href='http://www.expertsguide.info/2010/09/common-mistakes-and-points-to-remember-in-mysql/' rel='bookmark' title='Permanent Link: Common mistakes and points to remember in MySQL'>Common mistakes and points to remember in MySQL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/09/how-to-know-memory-used-by-current-running-tasks-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Common mistakes and points to remember in MySQL</title>
		<link>http://www.expertsguide.info/2010/09/common-mistakes-and-points-to-remember-in-mysql/</link>
		<comments>http://www.expertsguide.info/2010/09/common-mistakes-and-points-to-remember-in-mysql/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 11:20:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=363</guid>
		<description><![CDATA[<p>Some common mistakes we often commit while coding in PHP to access MySQL DB (Database).</p>
<p>1. For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements like INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/09/common-mistakes-and-points-to-remember-in-mysql/">Common mistakes and points to remember in MySQL</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/sanitize-user-input-with-mysql/' rel='bookmark' title='Permanent Link: Sanitize User Input with MySQL'>Sanitize User Input with MySQL</a></li>
<li><a href='http://www.expertsguide.info/2010/08/how-to-optimize-php-code/' rel='bookmark' title='Permanent Link: How to optimize PHP code'>How to optimize PHP code</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Some common mistakes we often commit while coding in PHP to access MySQL DB (Database).</p>
<p>1. For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on <strong>success</strong>, or <strong>FALSE</strong> on error. For other type of SQL statements like INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error (i.e. boolean result and <strong>not a resource</strong>). Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.</p>
<pre class="brush:php">$sql = "UPDATE tablename SET id='123'";
$result = mysql_query($sql) or die("Error: Cannot execute SQL : ".mysql_error() );
if($result !==  false) // correct, context check
{
    $num_rows = mysql_num_rows($result);      //incorrect   rather use mysql_affected_rows()
    while ($row = mysql_fetch_assoc($result))   //incorrect for UPDATE statement
    { }
}</pre>
<p>The returned result resource (by SELECT, SHOW, DESCRIBE, EXPLAIN etc) should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.</p>
<p>mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.</p>
<p>A resource can be checked by the following,</p>
<pre class="brush:php">$db_link = @mysql_connect('localhost', 'mysql_user', 'mysql_pass');
if (!is_resource($db_link))  {
   die('Can not connect : ' . mysql_error());
}</pre>
<p>mysql_free_result() will free all memory occupied by the resultset.</p>
<p>mysql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return<strong> large result sets</strong>. All associated result memory is automatically freed at the end of the script&#8217;s execution. Using this function may actually increase the amount of memory used (use it when you know the resultset is really large).  Use memory_get_usage() at the end of the script to see the memory usage by MySQL.</p>
<p>2. We sometimes pass the user inputs directly to the SQL statements which is a big security threat. Sanitize the user inputs before passing them to SQLs.</p>
<pre class="brush:php">$query = sprintf( 'SELECT id, name FROM People WHERE name = IN (%s)',
implode(',', array_map( 'mysql_real_escape_string', $names_array )) );

function my_real_escape_string($string)
{
   if (get_magic_quotes_gpc())
      $string = stripslashes($string); //if magic quotes are enabled, it automatically prepends backslash
   return mysql_real_escape_string($string);
}</pre>
<p>3. Number of rows affected is 0 (zero) if same value is being updated using UPDATE in MySQL (actually it doesn&#8217;t update if value is same) hence creating a wrong impression that our update statement failed and giving error. So proper check should be done before dumping an error.<br />
Also, remember the parameter passed to mysql_affected_rows() is a link resource NOT a resultset.<br />
While that to mysql_num_rows() is a resutset.  </p>
<p>4. Instead of executing SQL commands in a loop try executing it once only and store the output in some variavle or array. This increases efficiency and reduces execution time.<br />
Wrong Approach,</p>
<pre class="brush:php">$res = myql_query($first_query) or die ("Error 1");
while($row = mysql_fetch_row($res) )
{   //faster than mysql_fetch_assoc()
    $second_query = "select name from table where id= $row[0]";
    $res = myql_query($second_query) or die ("Error 2");
    while($row2 = mysql_fetch_row($res) )
    {
       ....
    }
}</pre>
<p>Right Approach,</p>
<pre class="brush:php">$str="";
$res = myql_query($first_query) or die ("Error 1");
while($row = mysql_fetch_row($res) )
{   //faster than mysql_fetch_assoc()
    $str .= $row[0].',';
}
//remove last comma
$str = (substr($str,-1) == ',') ? substr($str, 0, -1) : $str;

$second_query = "select name from table where id IN ($str)";
$res = myql_query($second_query) or die ("Error 2");
while($row2 = mysql_fetch_row($res) )
{
       ....
}</pre>
<p>5. Always fetch definite columns from SQL and try to avoid * in select statements. It unnecessarily fetches all the columns which might not be needed.</p>
<pre class="brush:php">SELECT * from table            //bad
SELECT id,name from table   //good</pre>
<p>6. Open connections time out after a default setting (in MySQL conf file). But still you should take the honour of closing the connections once you are done with it. If you don&#8217;t, PHP will close it on exiting.</p>
<p>Useful SQLs to check performance:<br />
a. Query &#8220;SHOW PROCESSLIST&#8221; shows which processes in MySQL are currently running.<br />
b. Query &#8220;SHOW STATUS&#8221; shows the current number of connections.</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/sanitize-user-input-with-mysql/' rel='bookmark' title='Permanent Link: Sanitize User Input with MySQL'>Sanitize User Input with MySQL</a></li>
<li><a href='http://www.expertsguide.info/2010/08/how-to-optimize-php-code/' rel='bookmark' title='Permanent Link: How to optimize PHP code'>How to optimize PHP code</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/09/common-mistakes-and-points-to-remember-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to increase file upload limit using .htaccess</title>
		<link>http://www.expertsguide.info/2010/09/how-to-increase-file-upload-limit-using-htaccess/</link>
		<comments>http://www.expertsguide.info/2010/09/how-to-increase-file-upload-limit-using-htaccess/#comments</comments>
		<pubDate>Sat, 11 Sep 2010 14:35:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Web Master]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=360</guid>
		<description><![CDATA[<p>Sometimes sever settings do not allow you to upload files more than a fixed limit (usually 2 MB). But, some websites might require allowing files more than this limit. In such cases we need to set some options in httpd.conf configuaretion file. This sometimes is not allowed on shared servers. &#8220;.htaccess&#8221; file comes to the rescue.</p>
<p>Put <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/09/how-to-increase-file-upload-limit-using-htaccess/">How to increase file upload limit using .htaccess</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/' rel='bookmark' title='Permanent Link: How to parse PHP in html pages'>How to parse PHP in html pages</a></li>
<li><a href='http://www.expertsguide.info/2010/08/stop-indexing-of-files-in-a-directory-using-htaccess/' rel='bookmark' title='Permanent Link: Stop indexing files in a directory using .htaccess'>Stop indexing files in a directory using .htaccess</a></li>
<li><a href='http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/' rel='bookmark' title='Permanent Link: Use .htaccess to rewrite/redirect requests'>Use .htaccess to rewrite/redirect requests</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Sometimes sever settings do not allow you to upload files more than a fixed limit (usually 2 MB). But, some websites might require allowing files more than this limit. In such cases we need to set some options in httpd.conf configuaretion file. This sometimes is not allowed on shared servers. &#8220;.htaccess&#8221; file comes to the rescue.</p>
<p>Put the below lines in a plain text file. Upload that to your home directory on your web-server and rename it as &#8220;.htaccess&#8221;. This would allow an upload of upto 20 MB file sizes.</p>
<pre class="brush:plain">php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200</pre>
<p>Enjoy uploading !</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/' rel='bookmark' title='Permanent Link: How to parse PHP in html pages'>How to parse PHP in html pages</a></li>
<li><a href='http://www.expertsguide.info/2010/08/stop-indexing-of-files-in-a-directory-using-htaccess/' rel='bookmark' title='Permanent Link: Stop indexing files in a directory using .htaccess'>Stop indexing files in a directory using .htaccess</a></li>
<li><a href='http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/' rel='bookmark' title='Permanent Link: Use .htaccess to rewrite/redirect requests'>Use .htaccess to rewrite/redirect requests</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/09/how-to-increase-file-upload-limit-using-htaccess/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to compare the execution time of PHP code blocks</title>
		<link>http://www.expertsguide.info/2010/09/how-to-compare-the-execution-time-of-php-code-blocks/</link>
		<comments>http://www.expertsguide.info/2010/09/how-to-compare-the-execution-time-of-php-code-blocks/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 16:03:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=355</guid>
		<description><![CDATA[<p>How to compare the execution time of PHP code blocks?</p>
<p>Sometimes we want to test our code for efficiency and execution time by comparing it with other code. Here&#8217;s how you can compare two code blocks in PHP and decide which one is faster (helps in optimization of code).</p>
$str = '1,2,3,4,';   //we will trim the <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/09/how-to-compare-the-execution-time-of-php-code-blocks/">How to compare the execution time of PHP code blocks</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/how-to-optimize-php-code/' rel='bookmark' title='Permanent Link: How to optimize PHP code'>How to optimize PHP code</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-remove-last-comma-from-a-string-in-php/' rel='bookmark' title='Permanent Link: How to remove last comma from a string in PHP?'>How to remove last comma from a string in PHP?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How to compare the execution time of PHP code blocks?</p>
<p>Sometimes we want to test our code for efficiency and execution time by comparing it with other code. Here&#8217;s how you can compare two code blocks in PHP and decide which one is faster (helps in optimization of code).</p>
<pre class="brush:php">$str = '1,2,3,4,';   //we will trim the trailing comma

$time = microtime(); $micro1 = explode(' ', $time);
echo "Started at $time\n";    //Note the starting time.

$str1 = (substr($str,-1) == ',') ? substr($str, 0, -1) : $str;

$time = microtime(); $micro2 = explode(' ', $time);
echo "Took ", bcsub($micro2[1],$micro1[1]), bcsub($micro2[0],$micro1[0],6)," secs\n";

$str2 = preg_replace("/,*$/", '', $str);

$time = microtime(); $micro3 = explode(' ', $time);
echo "Took ", bcsub($micro3[1],$micro2[1]), bcsub($micro3[0],$micro2[0],6)," secs\n";
</pre>
<p><strong>Output:</strong><br />
It ran it a few times on command-line on my local computer and it gave,</p>
<p>D:\&gt;php New9.php<br />
Started at 0.59481000 1283787551<br />
Took 00.000610 secs<br />
Took 00.001064 secs</p>
<p>D:\&gt;php New9.php<br />
Started at 0.01657800 1283787594<br />
Took 00.000658 secs<br />
Took 00.001177 secs</p>
<p>D:\&gt;php New9.php<br />
Started at 0.29726000 1283787644<br />
Took 00.000390 secs<br />
Took 00.000557 secs</p>
<p>D:\&gt;php New9.php<br />
Started at 0.57921400 1283787650<br />
Took 00.000614 secs<br />
Took 00.001060 secs</p>
<p>D:\&gt;php New9.php<br />
Started at 0.68782700 1283787653<br />
Took 00.000372 secs<br />
Took 00.000497 secs</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/how-to-optimize-php-code/' rel='bookmark' title='Permanent Link: How to optimize PHP code'>How to optimize PHP code</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-remove-last-comma-from-a-string-in-php/' rel='bookmark' title='Permanent Link: How to remove last comma from a string in PHP?'>How to remove last comma from a string in PHP?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/09/how-to-compare-the-execution-time-of-php-code-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to optimize PHP code</title>
		<link>http://www.expertsguide.info/2010/08/how-to-optimize-php-code/</link>
		<comments>http://www.expertsguide.info/2010/08/how-to-optimize-php-code/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 17:05:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=347</guid>
		<description><![CDATA[<p>While writing PHP code, you should keep following points in mind, to make your code run efficiently and quickly.
Most the optimization depends on the tuning of the webserver, compiling PHP with correct configuration options and cache usage. But, still, some what optimization can be achieved, if you,
1) &#8220;Loops&#8221; (for, foreach, while) are the sections which take <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/how-to-optimize-php-code/">How to optimize PHP code</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/usefull-php-array-functions/' rel='bookmark' title='Permanent Link: Usefull PHP array functions'>Usefull PHP array functions</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/' rel='bookmark' title='Permanent Link: How to get elements from one array but not in another array'>How to get elements from one array but not in another array</a></li>
<li><a href='http://www.expertsguide.info/2010/08/sanitize-user-input-with-mysql/' rel='bookmark' title='Permanent Link: Sanitize User Input with MySQL'>Sanitize User Input with MySQL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>While writing PHP code, you should keep following points in mind, to make your code run efficiently and quickly.<br />
Most the optimization depends on the tuning of the webserver, compiling PHP with correct configuration options and cache usage. But, still, some what optimization can be achieved, if you,<br />
1) &#8220;Loops&#8221; (for, foreach, while) are the sections which take most of the time of the program execution. Optimization of the loops should be the first thing you should do. Nested loops (loop inside loop) call for more attention. Take the non-variables (for which value does not change) outside the loop. eg,</p>
<pre class="brush:php">for($i=0; $i&lt;count($array); $i++)  //not good</pre>
<p>If the array length (max iterations for the loop) is not changing, calculated it outside loop body or in the initialization portion (before first semicolon). It does not get calculated in every iteration and hence reduces load.</p>
<pre class="brush:php">$length = count($array);
for($i=0; $i&lt;$length; $i++) //good</pre>
<p>or</p>
<pre class="brush:php">for($i=0, $length=count($array); $i&lt;$length; $i++) //good (it is same as above)</pre>
<p>2) When using arrays or MySQL result objects use &#8220;while&#8221; or &#8220;foreach&#8221; loop. This would save us extra step of incrementing/decrementing the counter in every iteration, eg,</p>
<pre class="brush:php">while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
}
mysql_free_result($result);  // release the memory</pre>
<p>3) Try to avoid regular expression engine overhead wherever possible.<br />
To search a substring, PHP function strpos() is fastest, then preg_match() and then ereg().<br />
In the same way, PHP function str_replace() is faster than preg_replace(), which is faster than ereg_replace().</p>
<p>4) Use &#8220;switch&#8221; in case of multiple &#8220;if&#8221;s and &#8220;else&#8221;s. Keep most frequently occuring cases on top in the switch body. If some common cases are still there in the default section, explicitly define them at the top to prevent condition checks of multiple cases. If case condition matches at the top itself, execution comes out immediately, hence program runs faster.</p>
<p>5) Release memory by unsetting variables (PHP function unset(); ) which are no more used. Do it especially for resources and large arrays. For releasing MySQL resources use mysql_free_result(), close the DB connection as soon as you are done with it.</p>
<p>6) Use multiple parameters of echo instead of string concatenation and then echoing it, eg,</p>
<pre class="brush:php">echo $var1.$var2.$var3;  //not good
echo $var1, $var2, $var3;  //good</pre>
<p>7) Use single quote instead of double quotes when there is no varible to be printed by echo.</p>
<pre class="brush:php">echo "Hello World"; //not good
echo 'Hello World'; //good
echo 'Hello ', $username, ' welcome back';</pre>
<p>8 ) Use PHP function isset() to check the existence of a variable, before using this variable in any condition or calculation.</p>
<pre class="brush:php">if ( strcmp($_POST['id'], '12345')==0  ) //not good
//if id is not set there's no point in comparision
if (isset($_POST['id']) &amp;&amp; ( strcmp($_POST['id'], '12345')==0 ) ) //good</pre>
<p>9) mt_rand() is four times faster than rand().<br />
If you need to create random numbers, with or without the range, use mt_rand() instead of rand()</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/usefull-php-array-functions/' rel='bookmark' title='Permanent Link: Usefull PHP array functions'>Usefull PHP array functions</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/' rel='bookmark' title='Permanent Link: How to get elements from one array but not in another array'>How to get elements from one array but not in another array</a></li>
<li><a href='http://www.expertsguide.info/2010/08/sanitize-user-input-with-mysql/' rel='bookmark' title='Permanent Link: Sanitize User Input with MySQL'>Sanitize User Input with MySQL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/how-to-optimize-php-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTTP Authentication in URL not working in IE</title>
		<link>http://www.expertsguide.info/2010/08/http-authentication-in-url-not-working-in-ie/</link>
		<comments>http://www.expertsguide.info/2010/08/http-authentication-in-url-not-working-in-ie/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 13:22:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Web Master]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=344</guid>
		<description><![CDATA[<p>IE (Internet Explorer) doesn&#8217;t work with user names and passwords in Web site addresses URLs (HTTP/S).
Though, IE versions 3.0 to 6.0 support this.</p>
<p>The following URL syntax may not work in Internet Explorer or in Windows Explorer,
http(s)://username:password@mydomain.com</p>
<p>Reason:
Such URL syntax is used to automatically send username/password to a Web site which requires basic authentication.
A hacker may exploit this <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/http-authentication-in-url-not-working-in-ie/">HTTP Authentication in URL not working in IE</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/' rel='bookmark' title='Permanent Link: Button tag inside anchor not working in IE'>Button tag inside anchor not working in IE</a></li>
<li><a href='http://www.expertsguide.info/2010/07/css-font-size-property-not-working-in-internet-explorer/' rel='bookmark' title='Permanent Link: CSS font-size property not working in Internet Explorer'>CSS font-size property not working in Internet Explorer</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>IE (Internet Explorer) doesn&#8217;t work with user names and passwords in Web site addresses URLs (HTTP/S).<br />
Though, IE versions 3.0 to 6.0 support this.</p>
<p>The following URL syntax may not work in Internet Explorer or in Windows Explorer,<br />
http(s)://username:password@mydomain.com</p>
<p>Reason:<br />
Such URL syntax is used to automatically send username/password to a Web site which requires basic authentication.<br />
A hacker may exploit this nomenclature and make a hyperlink which looks like opening a legal/intended Web site but in reality opens a another, e.g., http://www.expertsguide.info@example.com doesn&#8217;t open http://www.expertsguide.info which you would think should, rather opens http://example.com</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/' rel='bookmark' title='Permanent Link: Button tag inside anchor not working in IE'>Button tag inside anchor not working in IE</a></li>
<li><a href='http://www.expertsguide.info/2010/07/css-font-size-property-not-working-in-internet-explorer/' rel='bookmark' title='Permanent Link: CSS font-size property not working in Internet Explorer'>CSS font-size property not working in Internet Explorer</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/http-authentication-in-url-not-working-in-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sanitize User Input with MySQL</title>
		<link>http://www.expertsguide.info/2010/08/sanitize-user-input-with-mysql/</link>
		<comments>http://www.expertsguide.info/2010/08/sanitize-user-input-with-mysql/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 22:32:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=331</guid>
		<description><![CDATA[<p>Never believe your user would always provide you with the correct or expected input. People can play around with your security and mess up with the important data. You might end up losing your customers or their data (emails or passwords) or may be your website.</p>
<p>Always protect your code and database from hacks and intrusions by <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/sanitize-user-input-with-mysql/">Sanitize User Input with MySQL</a></span>]]></description>
			<content:encoded><![CDATA[<p>Never believe your user would always provide you with the correct or expected input. People can play around with your security and mess up with the important data. You might end up losing your customers or their data (emails or passwords) or may be your website.</p>
<p>Always protect your code and database from hacks and intrusions by sanitizing the user inputs.</p>
<p>How to sanitize user input?<br />
1) Put a size limit on every input field.</p>
<pre class="brush:php;">substr($_POST['name'], 0, 50);</pre>
<p>2) Check whether input&#8217;s context is per expected or not, i.e., where you are expecting an integer do not entertain alphabets or others.</p>
<pre class="brush:php;">is_numeric($_POST['name'])</pre>
<p>3) Type cast inputs wherever necessary.</p>
<pre class="brush:php;">$id = (int)$user_id;
// or use sprintf
$query = sprintf("SELECT * FROM users WHERE id='%d'", mysql_real_escape_string($id) );
</pre>
<p>4) Process them through the PHP&#8217;s function mysql_real_escape_string(). This function escapes character which have special meaning to SQL engines.</p>
<pre class="brush:php;">$address = mysql_real_escape_string($address, $dblink);
//do it on whole user data in one go
 $_POST = mysql_real_escape_array($_POST);
//or for more control
 foreach ($_POST as $key =&gt; $value) {
 $_POST[$key] = mysql_real_escape_string($value);
 } 

//If magic_quotes_gpc is enabled, apply stripslashes() first before
//applying mysql_real_escape_string to the data.
//Else,this function will escape the data twice.</pre>
<p>5) Never pass user inputs directly to the SQLs.</p>
<pre class="brush:php;">
//Never do this
$sql = "Select * from tablename where $condition-from-user"
</pre>
<p>6) Try to hard-code SQLs as much as possible.<br />
7) Do not fetch * (Select *) wherever you know what you need to fetch (Select name, id).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/sanitize-user-input-with-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Text Document on right click menu missing</title>
		<link>http://www.expertsguide.info/2010/08/new-text-document-on-right-click-menu-missing/</link>
		<comments>http://www.expertsguide.info/2010/08/new-text-document-on-right-click-menu-missing/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 02:14:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=321</guid>
		<description><![CDATA[<p>Sometimes when we install or uninstall third party softwares we even end up losing our registry option of creating .txt files using right mouse click -&#62; New -&#62;&#8221;TXT document&#8221;.</p>
<p>If you have suffered the same, no worries, here&#8217;s the solution for Windows XP.</p>
<p>Put this registry entry into a plain text document and name it &#8220;something.reg&#8221;. Note, extension <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/new-text-document-on-right-click-menu-missing/">New Text Document on right click menu missing</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/' rel='bookmark' title='Permanent Link: how to set or change a default printer on windows?'>how to set or change a default printer on windows?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/' rel='bookmark' title='Permanent Link: How to show or hide text using javascript?'>How to show or hide text using javascript?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/' rel='bookmark' title='Permanent Link: Button tag inside anchor not working in IE'>Button tag inside anchor not working in IE</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Sometimes when we install or uninstall third party softwares we even end up losing our registry option of creating .txt files using right mouse click -&gt; New -&gt;&#8221;TXT document&#8221;.</p>
<p>If you have suffered the same, no worries, here&#8217;s the solution for Windows XP.</p>
<p>Put this registry entry into a plain text document and name it &#8220;something.reg&#8221;. Note, extension .reg is important here. Save it and double click it. It asks you to modify the registry entry, say Yes and successfully done prompt should appear. We are done now. Restart your computer and see if it (right click-&gt;New-&gt;TEXT Document) is there.</p>
<p>Alternatively you can download this file from <a title="TXT Registry in WIndows" href="http://www.expertsguide.info/download/Create-TXT-registry.reg.removeme" target="_blank">here</a>, change the extension (remove .txt) and double click it.</p>
<p>Windows Registry Editor Version 5.00</p>
<p>[HKEY_CLASSES_ROOT\.txt]<br />
&#8220;Content Type&#8221;=&#8221;text/plain&#8221;<br />
@=&#8221;txtfile&#8221;<br />
&#8220;PerceivedType&#8221;=&#8221;text&#8221;</p>
<p>[HKEY_CLASSES_ROOT\.txt\OpenWithList]</p>
<p>[HKEY_CLASSES_ROOT\.txt\PersistentHandler]<br />
@=&#8221;{5e941d80-bf96-11cd-b579-08002b30bfeb}&#8221;</p>
<p>[HKEY_CLASSES_ROOT\.txt\shell]</p>
<p>[HKEY_CLASSES_ROOT\.txt\shell\open]</p>
<p>[HKEY_CLASSES_ROOT\.txt\shell\open\command]<br />
@=&#8221;notepad.exe %1&#8243;</p>
<p>[HKEY_CLASSES_ROOT\.txt\ShellNew]<br />
&#8220;NullFile&#8221;=&#8221;"</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/' rel='bookmark' title='Permanent Link: how to set or change a default printer on windows?'>how to set or change a default printer on windows?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/' rel='bookmark' title='Permanent Link: How to show or hide text using javascript?'>How to show or hide text using javascript?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/' rel='bookmark' title='Permanent Link: Button tag inside anchor not working in IE'>Button tag inside anchor not working in IE</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/new-text-document-on-right-click-menu-missing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Stop indexing files in a directory using .htaccess</title>
		<link>http://www.expertsguide.info/2010/08/stop-indexing-of-files-in-a-directory-using-htaccess/</link>
		<comments>http://www.expertsguide.info/2010/08/stop-indexing-of-files-in-a-directory-using-htaccess/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 15:53:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Web Master]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=308</guid>
		<description><![CDATA[<p>How to stop indexing of files in a directory using .htaccess?</p>
<p>Sometimes we do not want to show all the files in a directory (which by default is a behavior of web servers).
That can be done using htaccess file.
Though there&#8217;s a simple solution to this, put an index.html file showing a decent message &#8220;Not authorized to access <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/stop-indexing-of-files-in-a-directory-using-htaccess/">Stop indexing files in a directory using .htaccess</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/block-robots-from-accessing-webpages/' rel='bookmark' title='Permanent Link: Block robots from accessing webpages using .htaccess'>Block robots from accessing webpages using .htaccess</a></li>
<li><a href='http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/' rel='bookmark' title='Permanent Link: Use .htaccess to rewrite/redirect requests'>Use .htaccess to rewrite/redirect requests</a></li>
<li><a href='http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/' rel='bookmark' title='Permanent Link: How to parse PHP in html pages'>How to parse PHP in html pages</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How to stop indexing of files in a directory using .htaccess?</p>
<p>Sometimes we do not want to show all the files in a directory (which by default is a behavior of web servers).<br />
That can be done using htaccess file.<br />
Though there&#8217;s a simple solution to this, put an index.html file showing a decent message &#8220;Not authorized to access this&#8221;. But that will have little control over management.</p>
<p>What if we want to have more control and do it at the initial stage only?<br />
Use .htaccess file.</p>
<p>Put this in your htaccess file</p>
<pre class="brush:plain">IndexIgnore *</pre>
<p>here * (asterisk) matches all the files so none would be displayed.</p>
<p>If you do not want to show .css or .conf or .php or .sh files only and let other files being shown, then,</p>
<pre class="brush:plain">IndexIgnore *.css
IndexIgnore *.php
IndexIgnore *.sh
IndexIgnore *.conf</pre>
<p>or in a single line</p>
<pre class="brush:plain">IndexIgnore *.css *.php *.conf *.sh</pre>
<p>This can be made to work for relative paths also, if you want to put all your htaccess statements in a single file at root level (recommended)</p>
<pre class="brush:plain">IndexIgnore /common-files/scripts/*</pre>
<p>To make some file like &#8220;myfile.html&#8221; your default file (instead of index.html) which opens when a user enters a URL to access some directory, then use,</p>
<pre class="brush:plain">DirectoryIndex myfile.html</pre>
<p>You can specify more than one file names, in case first is not found then immediate next one would be opened.</p>
<pre class="brush:plain">DirectoryIndex myfile_1.html myfile_2.html</pre>
<p>On the contrary, if you want to show file index under a directory (opposite of stopping index) then use this,</p>
<pre class="brush:plain">Options +Indexes</pre>
<p>Secure your files from accidental display to the users,</p>
<pre class="brush:plain">&lt;Files ".htaccess"&gt;
    Order Deny,Allow
    Deny from all
    Allow from 122.255.43.3
&lt;/Files&gt;</pre>
<p>Use regular expressions (using ~) to specify file names (to secure files other than .htaccess)</p>
<pre class="brush:plain">&lt;Files ~ "\.(gif|jpe?g|png)$"&gt;
   Order Deny,Allow
   Deny from all
  Allow from 122.255.43.3
&lt;/Files&gt;</pre>
<p>or</p>
<pre class="brush:plain">&lt;FilesMatch "\.(gif|jpe?g|png)$"&gt;</pre>
<p> </p>
<p>Keep checking <a title="expertsguide.info" href="../" target="_blank">this article</a> for more updates.</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/block-robots-from-accessing-webpages/' rel='bookmark' title='Permanent Link: Block robots from accessing webpages using .htaccess'>Block robots from accessing webpages using .htaccess</a></li>
<li><a href='http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/' rel='bookmark' title='Permanent Link: Use .htaccess to rewrite/redirect requests'>Use .htaccess to rewrite/redirect requests</a></li>
<li><a href='http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/' rel='bookmark' title='Permanent Link: How to parse PHP in html pages'>How to parse PHP in html pages</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/stop-indexing-of-files-in-a-directory-using-htaccess/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Block robots from accessing webpages using .htaccess</title>
		<link>http://www.expertsguide.info/2010/08/block-robots-from-accessing-webpages/</link>
		<comments>http://www.expertsguide.info/2010/08/block-robots-from-accessing-webpages/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 12:43:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Web Master]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=296</guid>
		<description><![CDATA[<p>How to block</p>
<p>Use htaccess file.
this is run by server and ensured by the server that the rules written in it are enforced.</p>
<p>On the other hand, robots.txt file is just a guideline file. Robots are not bound to follow it.</p>
<p>To ensure denial of all requests for the restricted directory, put the following in the .htaccess file (keep <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/block-robots-from-accessing-webpages/">Block robots from accessing webpages using .htaccess</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/' rel='bookmark' title='Permanent Link: Use .htaccess to rewrite/redirect requests'>Use .htaccess to rewrite/redirect requests</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How to block</p>
<p>Use htaccess file.<br />
this is run by server and ensured by the server that the rules written in it are enforced.</p>
<p>On the other hand, robots.txt file is just a guideline file. Robots are not bound to follow it.</p>
<p>To ensure denial of all requests for the restricted directory, put the following in the .htaccess file (keep it in the same directory),</p>
<pre class="brush:plain">deny from all</pre>
<p>Allow access from one IP only and deny others,</p>
<pre class="brush:plain">order deny, allow
deny from all
allow from 255.255.12.34
ErrorDocument 403 errordoc.html</pre>
<p>Allow access from a range of IPs (may be a LAN or a country),</p>
<pre class="brush:plain">order deny, allow
deny from all
allow from 255.255.0</pre>
<p>Deny access from certain IP (e.g. a bot),</p>
<pre class="brush:plain">order allow, deny
deny from 255.255.123.456
allow from all</pre>
<p>Block a bad bot</p>
<pre class="brush:plain">RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^dirtybot
RewriteRule ^(.*)$ http://emptypage/</pre>
<p>or use [F] to send Forbidden signal<br />
RewriteRule .* &#8211; [F]</p>
<p>Block more that one bots</p>
<pre class="brush:plain">RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^dirtybot [OR]
RewriteCond %{HTTP_USER_AGENT} ^badCrawler [OR]
RewriteCond %{HTTP_USER_AGENT} ^fakeOne
RewriteRule ^(.*)$ http://emptypage/</pre>
<p>Deny more than one IPs or bot IPs</p>
<pre class="brush:plain">order allow,deny
deny from 255.255.123.456
deny from 123.255.123.456
deny from 456.255.123.456
allow from all</pre>
<p>Deny more than one IPs or bot IPs ranges (may be countries)</p>
<pre class="brush:plain">order allow,deny
deny from 255.255.
deny from 123.456.
allow from all</pre>
<p>Block particular ISPs,</p>
<pre class="brush:plain">order allow,deny
deny from this-bad-isp.com
deny from subdomain.bad-isp.com
allow from all</pre>
<p>Block some referers or websites from accessing your content like images or css or js files</p>
<pre class="brush:plain">RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://.*somebadforum\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*example\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*lastexample\.com [NC]
RewriteRule .* - [F]</pre>
<p> </p>
<p>Keep checking regular updates on <a title="www.ExpertsGuide.info" href="http://www.expertsguide.info/" target="_self">http://www.expertsguide.info/</a></p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/' rel='bookmark' title='Permanent Link: Use .htaccess to rewrite/redirect requests'>Use .htaccess to rewrite/redirect requests</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/block-robots-from-accessing-webpages/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Use .htaccess to rewrite/redirect requests</title>
		<link>http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/</link>
		<comments>http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 19:48:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Web Master]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=233</guid>
		<description><![CDATA[<p>How to redirect or rewrite URLs using .htaccess?</p>
<p>File, called as .htaccess, can be used to rewrite URLs apart from doing other stuffs like application handlers etc.</p>
<p>We can do some potent manipulations with our links, like,</p>

Transforming long URL&#8217;s into short, easy to remember URLs
Transforming URLs having in-comprehensive query strings like &#8220;filename?id=carnivores&#38;cat=animals&#8221; into  human readable URLs like &#8220;livingthings/animals/carnivores&#8221;
Redirect missing pages. Instead of showing  <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/">Use .htaccess to rewrite/redirect requests</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/' rel='bookmark' title='Permanent Link: How to parse PHP in html pages'>How to parse PHP in html pages</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How to redirect or rewrite URLs using .htaccess?</p>
<p>File, called as .htaccess, can be used to rewrite URLs apart from doing other stuffs like <a title="Parse PHP in HTML" href="http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/" target="_blank">application handlers</a> etc.</p>
<p>We can do some potent manipulations with our links, like,</p>
<ul>
<li>Transforming long URL&#8217;s into short, easy to remember URLs</li>
<li>Transforming URLs having in-comprehensive query strings like &#8220;<span style="color: #888888;">filename?id=carnivores&amp;cat=animals</span>&#8221; into  human readable URLs like <span style="color: #888888;">&#8220;livingthings/animals/carnivores&#8221;</span></li>
<li>Redirect missing pages. Instead of showing  frustrating  messages like &#8220;<span style="color: #888888;">401 Page Not Found</span>&#8221; you can show your users a neat html pages showing a humble message like &#8220;<span style="color: #888888;">Your request seems to be having wrong structure. Please check your URL</span>&#8220;. Or &#8220;<span style="color: #888888;">We are under maintenance. Please be back after some time</span>&#8220;.</li>
<li>Preventing hot-linking. Hot linking is, a third party using your servers bandwidth to access some stuff from your server directly eg images, css, javascript etc.</li>
<li>Performing automatic language translation (keeping all language files under one directory), etc.</li>
</ul>
<p>Lets start writing our .htaccess file. We should put two lines (<span style="color: #888888;">Options +FollowSymlinks</span> and  <span style="color: #888888;">RewriteEngine on</span>) in almost all .htaccess files to start the writing engine (details out of scope).  I will skip these two lines in my examples, please remember to have them in your file. The third line specifies which directory to start from (make base directory). Note: In case you are putting htaccess file in some sub directory then RewriteBase should be written to point to that sub-directory else rewritten URLs (targets) will be relative to home directory of the domain.</p>
<p>1) How to rewrite http://www.host.com/somefile.html to http://www.host.com/somefile.php</p>
<pre class="brush:plain">Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html$ $1.php</pre>
<p>Forward slash (/) here means home directory of <span style="color: #888888;">http://www.host.com/)</span> (usually <span style="color: #888888;">public_html</span>)<br />
Therefore our rewrite rules would match only filenames &amp; paths which are just after http://www.host.com/ (here <span style="color: #888888;">somefile.html</span>)</p>
<p>^, (.*),  $ and $1 are all regular expression special characters having special meaning e.g, ^ is to match the start of the string (it is start anchor), similarly $ is end anchor. Do not get confused with $1, it is not an anchor. It carries the back-referenced data captured with the parentheses &#8220;(&#8221; and &#8220;)&#8221;. A dot &#8220;.&#8221; matches any character and an asterisk following this dot means zero or more characters. A dot preceded by a back slash <span style="color: #888888;">\.</span> matches the literal dot (and not any character). For more info please refer regular expression tutorials.</p>
<p>2) How to rewrite all language files to a language directory, say, <span style="color: #888888;">http://www.host.com/file.html</span> to <span style="color: #888888;">http://www.host.com/french/file.html</span></p>
<pre class="brush:plain">RewriteRule ^(.*)\.html$ french/$1.html</pre>
<p>3) How to permanently redirect old URLs to new ones (to secure old page ranks)</p>
<pre class="brush:plain">RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mynewdomain.com/$1 [R=301,L]</pre>
<p>Here [NC] refers to case insensitive match and R=301 gives the HTTP Response to the client as &#8220;Permanently moved&#8221; to new URL.<br />
It will tell crawlers not to discard old URLs from their index and drop the page rank rather replace old ones with new ones.<br />
or</p>
<pre class="brush:plain">Redirect permanent /oldhtmlfile.htm http://your-domain.com/newhtmlfile.htm</pre>
<p>This way we can either strip www. from our domain (or add it, if you want) to put away ambiguity (between http://domain.com and http://www.domain.com) for crawlers and maintain a uniform linkage with external websites. For crawlers both are different entities.</p>
<p>To strip www.</p>
<pre class="brush:plain">RewriteCond %{HTTP_HOST} ^www\.mydomain\.com
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=permanent,L]</pre>
<p>To add www.</p>
<pre class="brush:plain">RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=permanent,L]</pre>
<p>Note: Moved permanently response code can also be served using PHP but that is not as good as doing by .htaccess file.</p>
<pre class="brush:php">&lt;?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.mydomain.com" );
?&gt;</pre>
<p>4) How to catch query strings (?var=value&amp;var2=value2 etc) to readable ones, say, <span style="color: #888888;">http://www.host.com/file.php?cat=123</span> to <span style="color: #888888;">http://www.host.com/file.php/category/123</span></p>
<pre class="brush:plain">RewriteCond %{QUERY_STRING} cat=(.*)
RewriteRule ^file.php.* /file.php/category/%1 [R]</pre>
<p>This can be used to redirect (not only rewrite) a user to readable URL. [R] handles redirection. %{QUERY_STRING} a global variable, contains the whole query string. This can be used to support some old URL patterns (backward compatibility). Though the reverse of it would be used to show and store the human readable URLs while at server you still process them with old functionality, eg. your users remember and write URL like file/category/carnivores  while you still process them with file.php?id=123</p>
<pre class="brush:plain">RewriteRule ^file/catogory/canivores/ file.php?id=123</pre>
<p>Stop hotlinking of your images with,</p>
<pre class="brush:plain">RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?host\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://hpst.com/img/empty.gif [L]</pre>
<p>%{HTTP_REFERER} contains the name of the refereeing website (eg http://otherhost.com). [NC] means case insensitive match, [L] means last (end up) the conditions rule here (to start another brand new rule, in case).</p>
<p>5) You can create some Not found error message pages.</p>
<p>ErrorDocument 401 /my-401-page.php</p>
<p>In this case if anybody requests a page which is not there on the server, s/he would be presented my-401-page.php, which can do some logging task also.</p>
<p>6) Limit the number of simultaneous connections to a directory or whole website (homepage) by,</p>
<p>MaxClients 100</p>
<p>7) In case of error, you can show your users an email of system administrator</p>
<p>ServerAdmin  admin@mydomain.com</p>
<blockquote><p>How to debug rewrite rules in htaccess file?</p>
<p>a) Mostly, the problem could be that AllowOverride is not set to allow configuration directives.<br />
You should make sure an AllowOverride None is not in effect for the file scope in question by putting garbage in your .htaccess file and reload. If a server error is not generated, then you almost certainly have AllowOverride None in effect.</p>
<p>b) Check the apache error log file (check through cpanel) at the sever.</p>
<p>c) Use the [R] option (which redirects the browser) to redirect the rewritten URL into the browser&#8217;s address bar. This URL can be appended with the matched back-references. Hence we get the regular expression matched strings in URLs e.g.,</p>
<pre class="brush:plain">RewriteEngine On
RewriteRule ^(.*)$ /file.php/category/match=$1 [R]</pre>
<p>It will paste /file.php/category/match=&#8221;matched value here&#8221; in the address bar.</p>
<p>d) Close all instances of the browser while debugging.</p></blockquote>
<p>Keep checking <a title="expertsguide.info" href="http://www.expertsguide.info/" target="_blank">this article</a> for more updates.</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/' rel='bookmark' title='Permanent Link: How to parse PHP in html pages'>How to parse PHP in html pages</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/use-htaccess-to-rewriteredirect-requests/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>About ExpertsGuide.info</title>
		<link>http://www.expertsguide.info/2010/08/about-expertsguide-info/</link>
		<comments>http://www.expertsguide.info/2010/08/about-expertsguide-info/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 11:30:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=228</guid>
		<description><![CDATA[<p>This website is a platform to discuss your problems related to Web  Technologies, Programming Languages, Operating Systems (OS), Scripting  Languages, Markup Languages, Style-sheets, Web development tools,Web Administration etc. To  be specific, you might find here, articles or posts related to PHP,  Perl, HTML, UNIX, Javascript, AJAX, CSS, XML, XSL, C, C++, J2EE, <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/about-expertsguide-info/">About ExpertsGuide.info</a></span>]]></description>
			<content:encoded><![CDATA[<p>This website is a platform to discuss your problems related to Web  Technologies, Programming Languages, Operating Systems (OS), Scripting  Languages, Markup Languages, Style-sheets, Web development tools,Web Administration etc. To  be specific, you might find here, articles or posts related to PHP,  Perl, HTML, UNIX, Javascript, AJAX, CSS, XML, XSL, C, C++, J2EE, OS,  MySQL, other Databases etc.</p>
<p>You can register here and put up your solutions also. It’s all free.</p>
<p>You can find here, time to time, various tips and tricks related to  the above discussed topics. They would be published by the administrator  of this site and will be open to discussion.</p>
<p>Happy Programming!</p>
<p>Administrator,<br />
<a href="http://www.expertsguide.info">ExpertsGuide.info</a><br />
<a href="mailto:info@expertsguide.info">info@expertsguide.info</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/about-expertsguide-info/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parse XML or HTML</title>
		<link>http://www.expertsguide.info/2010/08/parse-xml-or-html/</link>
		<comments>http://www.expertsguide.info/2010/08/parse-xml-or-html/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 09:23:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=209</guid>
		<description><![CDATA[<p>Here&#8217;s a simple XML parser, with DOM Object, which can fetch values digging deep but in a few lines of code.
It uses namespace functinality(XPATH). The XML document must have defined namespaces.</p>
&#60;?php
$xml = &#60;&#60;&#60;EOT
&#60;?xml version="1.0" encoding="UTF-8"?&#62;
&#60;entry xmlns="http://www.w3.org/2005/Atom" xmlns:other="http://other.w3.org/other" &#62;
        &#60;id&#62;uYG7-sPwjFg&#60;/id&#62;
        &#60;published&#62;2009-05-17T18:29:31.000Z&#60;/published&#62;
&#60;/entry&#62;
EOT;
$doc = new DOMDocument;
$doc-&#62;loadXML($xml);
$xpath =  DOMXPath($doc);
$xpath-&#62;registerNamespace('atom', "http://www.w3.org/2005/Atom");

$xpath_str = '//atom:entry/atom:published/text()';

$entries = $xpath-&#62;evaluate($xpath_str);

print $entries-&#62;item(0)-&#62;nodeValue ."\n";

?&#62;

<p>You can work with HTML <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/parse-xml-or-html/">Parse XML or HTML</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/' rel='bookmark' title='Permanent Link: How to parse PHP in html pages'>How to parse PHP in html pages</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/' rel='bookmark' title='Permanent Link: How to get elements from one array but not in another array'>How to get elements from one array but not in another array</a></li>
<li><a href='http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/' rel='bookmark' title='Permanent Link: Access Form objects in case of multiple forms'>Access Form objects in case of multiple forms</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple XML parser, with DOM Object, which can fetch values digging deep but in a few lines of code.<br />
It uses namespace functinality(XPATH). The XML document must have defined namespaces.</p>
<pre class="brush:php">&lt;?php
$xml = &lt;&lt;&lt;EOT
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;entry xmlns="http://www.w3.org/2005/Atom" xmlns:other="http://other.w3.org/other" &gt;
        &lt;id&gt;uYG7-sPwjFg&lt;/id&gt;
        &lt;published&gt;2009-05-17T18:29:31.000Z&lt;/published&gt;
&lt;/entry&gt;
EOT;
$doc = new DOMDocument;
$doc-&gt;loadXML($xml);
$xpath =  DOMXPath($doc);
$xpath-&gt;registerNamespace('atom', "http://www.w3.org/2005/Atom");

$xpath_str = '//atom:entry/atom:published/text()';

$entries = $xpath-&gt;evaluate($xpath_str);

print $entries-&gt;item(0)-&gt;nodeValue ."\n";

?&gt;
</pre>
<p>You can work with HTML also</p>
<pre class="brush:php">
&lt;?php
$file = "htmlfilename.html";
$doc = new DOMDocument();    //DOM Object (XML/HTML)
$doc-&gt;loadHTMLFile($file);
$xpath = new DOMXpath($doc); //XPATH Object
//$elements = $xpath-&gt;query("//*[@id]");  //for everything with an id
//$elements = $xpath-&gt;query("/html/body/div[@id='yourTagIdHere']");  //for node data in a selected id
$elements = $xpath-&gt;query("*/div[@id='yourTagIdHere']"); // same as above with wildcard

if (!is_null($elements)) {         // before entring into the loop check if something is there
  foreach ($elements as $element) {
    echo "&lt;br/&gt;[". $element-&gt;nodeName. "]";

    $nodes = $element-&gt;childNodes;
    foreach ($nodes as $node) {
      echo $node-&gt;nodeValue. "\n";
    }
  }
}
?&gt;</pre>
<p>Another simple way for XML (no hardcoding) is,</p>
<pre class="brush:php">
&lt;?php
function list_xml($str) {
  $root = simplexml_load_string($str);
  list_node($root);
}

function list_node($node) {
  foreach ($node as $element) {
    echo $element. "\n";
    if ($element-&gt;children()) {
      echo "&lt;br/&gt;";
      list_node($element);
    }
  }
}
?&gt;</pre>
<p>Another one, simple but with hardcoding. Be careful using nested SimpleXML objects in double quoted strings, as they might not work as expected, you might need a curly brace to make them work.</p>
<pre class="brush:php">&lt;?php
$xmlstring = '&lt;root&gt;&lt;node&gt;123&lt;/node&gt;&lt;foo&gt;&lt;bar&gt;456&lt;/bar&gt;&lt;/foo&gt;&lt;/root&gt;'; 

$root = simplexml_load_string($xmlstring); 

echo "Node is: $root-&gt;node"; // Works: Node is 123
echo "Bar is: $root-&gt;foo-&gt;bar"; // Doesn't work, outputs: Bar is: -&gt;bar  (use curly brackets to fix)
echo "Bar is: {$root-&gt;foo-&gt;bar}"; // Works: Bar is 456 

?&gt;</pre>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/' rel='bookmark' title='Permanent Link: How to parse PHP in html pages'>How to parse PHP in html pages</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/' rel='bookmark' title='Permanent Link: How to get elements from one array but not in another array'>How to get elements from one array but not in another array</a></li>
<li><a href='http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/' rel='bookmark' title='Permanent Link: Access Form objects in case of multiple forms'>Access Form objects in case of multiple forms</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/parse-xml-or-html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A simple AJAX tutorial</title>
		<link>http://www.expertsguide.info/2010/08/a-simple-ajax-tutorial/</link>
		<comments>http://www.expertsguide.info/2010/08/a-simple-ajax-tutorial/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 23:13:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Js-AJAX]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=205</guid>
		<description><![CDATA[<p>AJAX powered webpages have an edge when response time and resource usage is the matter of concern. AJAX shows quick results within a blink of an eye. And the best part is user never gets to see the whole page refreshed again for simple responses.</p>
<p>Lets create a simple AJAX implemented webpage. and see how it works.</p>
<p>Create an HTML file named ajax.html. <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/a-simple-ajax-tutorial/">A simple AJAX tutorial</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/' rel='bookmark' title='Permanent Link: How to access elements having some Class using Javascript?'>How to access elements having some Class using Javascript?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/' rel='bookmark' title='Permanent Link: How to show or hide text using javascript?'>How to show or hide text using javascript?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>AJAX powered webpages have an edge when response time and resource usage is the matter of concern. AJAX shows quick results within a blink of an eye. And the best part is user never gets to see the whole page refreshed again for simple responses.</p>
<p>Lets create a simple AJAX implemented webpage. and see how it works.</p>
<p>Create an HTML file named ajax.html. Put the following code in it.</p>
<pre class="brush:js">&lt;html&gt;
&lt;head&gt;
&lt;script&gt;

function submitForm(url, str)
{
 var xmlhttp;
 xmlhttp=GetXmlHttpObject();
 if (xmlhttp==null)
 {
   alert ("Your browser does not support XMLHTTP!");
   return;
 }
 url=url+"?"+str;
 url=url+"&amp;sid="+Math.random();   //to prevent the server from using a cached file
 xmlhttp.onreadystatechange=function() {
 if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
 {
    document.getElementById('fruitresult').innerHTML = xmlhttp.responseText;
 }

 xmlhttp.open("GET",url,true);
 xmlhttp.send(null);
}

function GetXmlHttpObject()
{
/*
 try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
 catch (e)
 {
   try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
   catch (e2)
   {
     try {  xhr = new XMLHttpRequest();     }
     catch (e3) {  xhr = false;   }
   }
 }
*/
if (window.XMLHttpRequest)     // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();

if (window.ActiveXObject)     // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");

  return null;
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="fruitresult"&gt;&lt;/div&gt;
&lt;FORM method="POST" name="ajax" action=""&gt;
&lt;INPUT type="BUTTON" value="Submit"  ONCLICK="submitForm('script.php','fruit=1'); return false;"&gt;
&lt;/FORM&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Create a PHP file and save in the same directory where ajax.html is placed. Name this PHP script script.php (if you change the name you&#8217;ll have to change it in the submitForm function also)</p>
<pre class="brush:php">&lt;?php
$fruits = Array(1=&gt;"Apple", 2=&gt;"Banan", 3=&gt;"Orange");
if(isset($_REQUEST['fruit']))
  echo $fruits[$_REQUEST['fruit']];
else
  echo "Sorry";
?&gt;

Note: I have used an anonymous function in onreadystatechange event and created my xmlhttp object local (not global).
This is relly important as you might have problems in case you have made multiple calls to the same ajax file from a single HTML page.</pre>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/' rel='bookmark' title='Permanent Link: How to access elements having some Class using Javascript?'>How to access elements having some Class using Javascript?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/' rel='bookmark' title='Permanent Link: How to show or hide text using javascript?'>How to show or hide text using javascript?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/a-simple-ajax-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to send mail when Googlebot crawls a webpage of your website</title>
		<link>http://www.expertsguide.info/2010/08/send-mail-when-googlebot-crawls-a-webpage/</link>
		<comments>http://www.expertsguide.info/2010/08/send-mail-when-googlebot-crawls-a-webpage/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 13:16:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Master]]></category>
		<category><![CDATA[crawler intimation]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=176</guid>
		<description><![CDATA[<p>How to send an email, as soon as Googlebot crawls a webpage of your website, in PHP?</p>
<p>Many of us have always wished to get some kind of intimation as soon as Google (Googlebot to be specific) crawls our websites. Isn&#8217;t it?
Don&#8217;t know if there are any tools available for the same but what about developing a small <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/send-mail-when-googlebot-crawls-a-webpage/">How to send mail when Googlebot crawls a webpage of your website</a></span>]]></description>
			<content:encoded><![CDATA[<p>How to send an email, as soon as Googlebot crawls a webpage of your website, in PHP?</p>
<p>Many of us have always wished to get some kind of intimation as soon as Google (Googlebot to be specific) crawls our websites. Isn&#8217;t it?<br />
Don&#8217;t know if there are any tools available for the same but what about developing a small PHP script which does it for us?</p>
<p>The idea is to include (PHP include function) a small PHP script, in a webpage (probably homepage like index.php), which you want should intimate you, when it is being accessed by Google crawler, the great Googlebot. <img src='http://www.expertsguide.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Googlebot&#8217;s identity can be confirmed (not 100% though) by checking it&#8217;s &#8220;HTTP User Agent&#8221; along with reverse and forward DNS lookup of the Googlebot IP address.</p>
<p>Refer, for more info, http://www.google.com/support/webmasters/bin/answer.py?hl=en&amp;answer=80553</p>
<p>Note: This is not a fool proof solution.</p>
<pre class="brush:php">&lt;?php
// <a href="http://www.expertsguide.info">www.expertsguide.info</a>
// Put this code in some file, call that file from other weppages.
// For other crawlers change $crawler_name
/* To run only for google comment the foreach loop, array $crawlers and uncomment below two lines
//$crawler_name = 'Googlebot' ;
//$crawler_host_str = '.googlebot.com' ; */
$crawlers = array('Googlebot'=&gt;'.googlebot.com',
                  'Yahoo! Slurp'=&gt;'.crawl.yahoo.net',
                  'MSNBot'=&gt; '.search.msn.com');
foreach($crawlers as $crawler_name =&gt; $crawler_host_str)
{
  if( isset($_SERVER['HTTP_USER_AGENT']) &amp;&amp;
      ( strpos($_SERVER['HTTP_USER_AGENT'], $crawler_name) !== false ) &amp;&amp;
      isset($_SERVER['REMOTE_ADDR']) )
  {
     $ip = $_SERVER['REMOTE_ADDR'];              //assume Googlebot never comes with fake IP
     $hostname = gethostbyaddr_timeout($ip);     //get the hostname (reverse DNS lookup)
     $hostip = gethostbyaddr_timeout($hostname); //get the hostname (forward DNS lookup)

     //if( preg_match("/$crawler_host_str/i",$hostname,$matches) &amp;&amp; (strcmp($ip,$hostip)==0) )
     if( (strpos($hostname, $crawler_host_str)!==false) &amp;&amp; (strcmp($ip,$hostip)==0) )   //no regex burden
     {
        $to       = "john.martin@example.com";               //put your email here
        $subject  = "$crawler_name just crawled your webpage";   //mail subject you want to see
        $message  = "";
        $message .= " $crawler_name HTTP User Agent: " . $_SERVER['HTTP_USER_AGENT'] . PHP_EOL;
        $message .= " IP: ".$ip. PHP_EOL;
        $message .= " Host name (reverse DNS lookup): ".$hostname . PHP_EOL;
        $message .= " Host IP (forward DNS lookup): ".$hostip . PHP_EOL;
        $message .= " Visited: ".$_SERVER['HTTP_HOST']."/".$_SERVER['SCRIPT_NAME'].PHP_EOL;

        mailit($to, $subject, $message);
     }
   }
}
///////////////////////////////////////////////////////////////////////////////////
function mailit($to, $subject, $message)
{
  $headers = '';
  // To send HTML mail, the Content-type header must be set, uncomment below two lines
  //$headers = 'MIME-Version: 1.0' . "\r\n";
  //$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  //$headers .= 'To: receiver@gmail.com' . "\r\n";
  //$headers .= 'Cc: somebody@gmail.com' . "\r\n";
  //$headers .= 'Bcc: somebody@yahoo.co.in' . "\r\n";
  $headers .= 'From: donotreply@example.com '."\r\n";

  $message = "Email was sent from http://www.mydomain.com \r\n ".$message."\r\n";

  if( ! mail($to, $subject, $message, $headers) ) {
    //echo "Message delivery failed...";
  }
}

function gethostbyaddr_timeout($ip)
{
   //The -W option makes host wait for wait seconds.
   //If wait is less than one, the wait interval is set to one second.
   //When the -w option is used, host will effectively wait forever for a reply.
   //DONT USE IT HERE.
  $output = `host -W 1 $ip`;
  if( ereg('.* pointer ([A-Za-z0-9.-]+)\..*', $output, $regs) ) {
    return $regs[1];   //hostname
  }
  elseif( ereg('.* address ([A-Za-z0-9.-]+).*', $output, $regs) )
  {
    return $regs[1];  //IP address
  }
  return $ip;
}
?&gt;</pre>
<p>Keep checking <a title="expertsguide.info" href="http://www.expertsguide.info/" target="_blank">this article</a> for more updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/send-mail-when-googlebot-crawls-a-webpage/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>How to parse PHP in html pages</title>
		<link>http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/</link>
		<comments>http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 09:22:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Master]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=173</guid>
		<description><![CDATA[<p>How to parse PHP in web pages having extension as .html / .htm?</p>
<p>This can be done using .htaccess file in the directory where you want all your .html files to be treated as php while still showing .html in the address bar.</p>
<p>Create a simple text file.  Put the following code in that file.</p>
RemoveHandler .html .htm
AddType application/x-httpd-php <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/">How to parse PHP in html pages</a></span>]]></description>
			<content:encoded><![CDATA[<p>How to parse PHP in web pages having extension as .html / .htm?</p>
<p>This can be done using .htaccess file in the directory where you want all your .html files to be treated as php while still showing .html in the address bar.</p>
<p>Create a simple text file.  Put the following code in that file.</p>
<pre class="brush:plain">RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html</pre>
<p>Save it and name it as &#8220;.htaccess&#8221; (on windows you might get problems in saving since it starts with a dot, in that case save it with any name, upload to server and then rename it) .<br />
Upload it to your web server to your WWW root or the directory where you want this functionality.</p>
<p>Now lets try if it works or not.</p>
<p>Create a test html file, name it something lie test.html<br />
Yes, extension should be .html<br />
Put some php code in the html (something like below)</p>
<pre class="brush:xml">&lt;html&gt;&lt;body&gt;
&lt;?php echo "Success, this is from PHP code inside HTML";  ?&gt;
&lt;/body&gt;&lt;/html&gt;</pre>
<p>Upload this html file (test.html) also to your web server (under the directory where you placed .htaccess ).<br />
Open this file in any browser.<br />
If you get the message &#8220;Success, this is from PHP code inside HTML&#8221;, time to cheer.</p>
<p>Keep checking <a title="expertsguide.info" href="http://www.expertsguide.info/" target="_blank">this article</a> for more updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/how-to-parse-php-in-html-pages/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Set time out while downloading files in PHP</title>
		<link>http://www.expertsguide.info/2010/08/set-time-out-while-downloading-files/</link>
		<comments>http://www.expertsguide.info/2010/08/set-time-out-while-downloading-files/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 19:02:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=168</guid>
		<description><![CDATA[<p>How to set a timeout while downloading a file from web in PHP?</p>
<p>Time out can be implemented in various ways in PHP e.g. by setting proper HTPP headers,  cURL options, PHP ini options, stream context options etc.</p>
<p>Method 1, using cURL timeout,</p>
&#60;?php
$url = 'http://www.example.com';
$text = content_from_curl($url);

function content_from_curl($url)
{
   $content = false;     // <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/08/set-time-out-while-downloading-files/">Set time out while downloading files in PHP</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-know-if-file-exists-on-web/' rel='bookmark' title='Permanent Link: How to know if a file exists on the web or not, in PHP?'>How to know if a file exists on the web or not, in PHP?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How to set a timeout while downloading a file from web in PHP?</p>
<p>Time out can be implemented in various ways in PHP e.g. by setting proper HTPP headers,  cURL options, PHP ini options, stream context options etc.</p>
<p>Method 1, using cURL timeout,</p>
<pre class="brush:php">&lt;?php
$url = 'http://www.example.com';
$text = content_from_curl($url);

function content_from_curl($url)
{
   $content = false;     // we will populate this with the downloaded content, if we get, else return false
   $curl = curl_init();
   curl_setopt($curl, CURLOPT_URL, $url);
   curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($curl, CURLOPT_TIMEOUT, 2);
   curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);

   if( ( $content = curl_exec($curl) ) === false )   {         //failure
      echo 'cURL error: ' . curl_error($ch);
   }
   else {
      //success
   }
   curl_close($curl);        // close the connection
   return $content;
}
?&gt;
</pre>
<p>Method 2, altering PHP ini option  <span style="color: #888888;">default_socket_timeout</span> ,</p>
<p>As of PHP 5.2.1 you can set the  &#8220;timeout&#8221; context option and pass the context to file_get_contents()</p>
<p>Note: Other time options  like execution time and input time would have no effect.</p>
<pre class="brush:php">&lt;?php
ini_set('default_socket_timeout', 10);
$url = "http://example.com/";
if( file_get_contents( urlencode($url) ) === false ) {
   // failure
} else {
   // success
}
?&gt;</pre>
<p>Method 3,</p>
<p>By setting timeout in stream context (<span style="color: #888888;">stream_context_create</span>) without messing with ini values</p>
<pre class="brush:php">&lt;?php
$timeout = 6;  //seconds
$options = array(
                  'http'=&gt;array(
                                 'method'=&gt;"GET",
                                 'header'=&gt;"Accept-language: en\r\n",
                                 'timeout' =&gt; $timeout )  );
$context = stream_context_create($options);
if( file_get_contents( urlencode($url), 0, $context) === false )  {
    // failure
} else {
    // success
}
?&gt;</pre>
<p>Method 4, using <span style="color: #888888;">stream_set_timeout</span> in sockets</p>
<pre class="brush:php">&lt;?php
$fp = fsockopen("www.example.com", 80);
if (!$fp) {
   echo "Unable to open\n";
}
else {
   fwrite($fp, "GET / HTTP/1.0\r\n\r\n");
   stream_set_timeout($fp, 2);
   $res = fread($fp, 2000);
   $info = stream_get_meta_data($fp);
   fclose($fp);

  if ($info['timed_out']) {
     echo 'Connection timed out!';
  }
  else {
     echo $res;
  }
}
?&gt;</pre>
<p>On the contrary, what if you want to increase the execution time of the script in PHP?<br />
set_time_limit() function can be called for this. When called, set_time_limit() restarts the timeout counter from zero.<br />
In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.</p>
<p>Keep checking <a title="expertsguide.info" href="http://www.expertsguide.info/" target="_blank">this article</a> for more updates.</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-know-if-file-exists-on-web/' rel='bookmark' title='Permanent Link: How to know if a file exists on the web or not, in PHP?'>How to know if a file exists on the web or not, in PHP?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/08/set-time-out-while-downloading-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS font-size property not working in Internet Explorer</title>
		<link>http://www.expertsguide.info/2010/07/css-font-size-property-not-working-in-internet-explorer/</link>
		<comments>http://www.expertsguide.info/2010/07/css-font-size-property-not-working-in-internet-explorer/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 14:09:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=143</guid>
		<description><![CDATA[<p>CSS (Cascading Style Sheete) font-size property does not work properly in Internet Explorer (IE) if spcified in this way,</p>
font-size: small
<p>or</p>
font-size: medium
<p>In mozilla firefox, it works fine.</p>
<p>Workaround:</p>
<p>Use em to specify the font size e.g.,</p>
&#60;style  type="text/css"&#62;
body {font-size: 0.75em;}
&#60;/style&#62;
<p> </p>
<p>Inheritance can cause problems, for nested tags, when em or % sizing of the text is used. For example, if you create a style like</p>
ul <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/css-font-size-property-not-working-in-internet-explorer/">CSS font-size property not working in Internet Explorer</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/' rel='bookmark' title='Permanent Link: Button tag inside anchor not working in IE'>Button tag inside anchor not working in IE</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>CSS (Cascading Style Sheete) font-size property does not work properly in Internet Explorer (IE) if spcified in this way,</p>
<pre class="brush:css">font-size: small</pre>
<p>or</p>
<pre class="brush:css">font-size: medium</pre>
<p>In mozilla firefox, it works fine.</p>
<p>Workaround:</p>
<p>Use em to specify the font size e.g.,</p>
<pre class="brush:css">&lt;style  type="text/css"&gt;
body {font-size: 0.75em;}
&lt;/style&gt;</pre>
<p> </p>
<p>Inheritance can cause problems, for nested tags, when em or % sizing of the text is used. For example, if you create a style like</p>
<pre class="brush:css">ul {font-size: 75%;}</pre>
<p>then a nested list (another ul tag inside ancestor ul) is set to 75% of 75%, making the text in the inner ul smaller than the rest of the list text.</p>
<p>Workaround for this is, create an additional descendent selector style</p>
<pre class="brush:css">ul ul {font-size:100%;}</pre>
<p>and put it after the earlier style. Hence there would two styles (or may be more as per the nesting),</p>
<pre class="brush:css">ul {font-size:75%;}
ul ul {font-size:100%;}</pre>
<p> </p>
<p>IE6 and earlier sometimes have problems displaying text when ony em units are used. To cope with this, there are two ways,</p>
<p>1) Either stick with percentage values like
<pre class="brush:css">font-size: 100%;}</pre>
<p> or<br />
2) Set the font size for the body of the page to percentage and then use em to size other text.</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/' rel='bookmark' title='Permanent Link: Button tag inside anchor not working in IE'>Button tag inside anchor not working in IE</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/css-font-size-property-not-working-in-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Button tag inside anchor not working in IE</title>
		<link>http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/</link>
		<comments>http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 12:49:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=136</guid>
		<description><![CDATA[<p>HTML button tag might not work as expected when put inside anchor tags.</p>
&#60;a href="http://www.expertsguide.info/"&#62;&#60;button type="button"&#62;Click Me to go to Experts Guide&#60;/button&#62;&#60;/a&#62;

<p>I works well in Mozilla Firefox but in Internet Explorer (IE) nothing happens on clicking it.</p>
<p>Workaround:</p>
<p>Put some javascript event inside onclick event handler. Redirect (or open a new window) in javascript to required URL.</p>
 &#60;a href="http://www.expertsguide.info/"&#62;&#60;button type="button" onclick="window.open('http://www.expertsguide.info/')"&#62;Click <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/">Button tag inside anchor not working in IE</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/' rel='bookmark' title='Permanent Link: Access Form objects in case of multiple forms'>Access Form objects in case of multiple forms</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/' rel='bookmark' title='Permanent Link: How to access elements having some Class using Javascript?'>How to access elements having some Class using Javascript?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/' rel='bookmark' title='Permanent Link: how to set or change a default printer on windows?'>how to set or change a default printer on windows?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>HTML button tag might not work as expected when put inside anchor tags.</p>
<pre class="brush:html">&lt;a href="http://www.expertsguide.info/"&gt;&lt;button type="button"&gt;Click Me to go to Experts Guide&lt;/button&gt;&lt;/a&gt;
</pre>
<p>I works well in Mozilla Firefox but in Internet Explorer (IE) nothing happens on clicking it.</p>
<p>Workaround:</p>
<p>Put some javascript event inside onclick event handler. Redirect (or open a new window) in javascript to required URL.</p>
<pre class="brush:js"> &lt;a href="http://www.expertsguide.info/"&gt;&lt;button type="button" onclick="window.open('http://www.expertsguide.info/')"&gt;Click Me to go to Experts Guide&lt;/button&gt;&lt;/a&gt;
</pre>
<p>or to open the URL in the same window,</p>
<pre class="brush:js"> &lt;a href="http://www.expertsguide.info/"&gt;&lt;button type="button" onclick="window.location('http://www.expertsguide.info/')"&gt;Click Me to go to Experts Guide&lt;/button&gt;&lt;/a&gt;
</pre>
<p>It should work in Mozilla Firefox as well as Internet Explorer (IE).</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/' rel='bookmark' title='Permanent Link: Access Form objects in case of multiple forms'>Access Form objects in case of multiple forms</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/' rel='bookmark' title='Permanent Link: How to access elements having some Class using Javascript?'>How to access elements having some Class using Javascript?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/' rel='bookmark' title='Permanent Link: how to set or change a default printer on windows?'>how to set or change a default printer on windows?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/button-tag-inside-anchor-not-working-in-i/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Find all files having some pattern using grep in UNIX</title>
		<link>http://www.expertsguide.info/2010/07/find-files-having-some-pattern-using-grep-in-unix/</link>
		<comments>http://www.expertsguide.info/2010/07/find-files-having-some-pattern-using-grep-in-unix/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 18:10:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[Web Master]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=120</guid>
		<description><![CDATA[<p>How to find all files under a directory, having a pattern, in their name or content,  in UNIX?</p>
<p>grep command can be used in conjunction with xargs to fetch filenames having some pattern in them.</p>
find  /search_dir/ -iname  "*.*" -print0 &#124; xargs -0 grep "PATTERN"
<p>where,
search_dir is the directory where search has to begin from
PATTERN is the pattern which needs to <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/find-files-having-some-pattern-using-grep-in-unix/">Find all files having some pattern using grep in UNIX</a></span>]]></description>
			<content:encoded><![CDATA[<p>How to find all files under a directory, having a pattern, in their name or content,  in UNIX?</p>
<p>grep command can be used in conjunction with xargs to fetch filenames having some pattern in them.</p>
<pre class="brush:bash">find  /search_dir/ -iname  "*.*" -print0 | xargs -0 grep "PATTERN"</pre>
<p>where,<br />
<span style="color: #4c4c4c;">search_dir</span> is the directory where search has to begin from<br />
<span style="color: #4c4c4c;">PATTERN</span> is the pattern which needs to search in the files.</p>
<p>Explanation,</p>
<ul>
<li><span style="color: #4c4c4c;">find</span> command searches the files under directory  <span style="color: #4c4c4c;">search_dir</span>.</li>
<li><span style="color: #000000;"><span style="color: #4c4c4c;">-name</span> (without i, case sensitive) tells the find command that argument following it should be a file name pattern</span></li>
<li><span style="color: #000000;">i when added to -name (<span style="color: #4c4c4c;">-iname</span>) makes file name search case insensitive (Note: this doesn&#8217;t affect case sensitivity of <span style="color: #4c4c4c;">PATTERN</span>) </span></li>
<li><span style="color: #000000;">*.* matches any filename with any extension</span></li>
<li><span style="color: #000000;">-print0 (zero) puts a null character as separator after every search result from find command (so that grep can properly work in case file names have space or newline). Even quotes can be used to handle spaces in file names.<br />
</span></li>
<li><span style="color: #000000;"><span style="color: #4c4c4c;">xargs</span> causes grep command to run on all the file names piped to it. Without <span style="color: #4c4c4c;">xargs</span>, the <span style="color: #4c4c4c;">grep</span> would try to apply <span style="color: #4c4c4c;">PATTERN</span> match on the file names itself and not their content.</span></li>
<li><span style="color: #000000;"><span style="color: #4c4c4c;">PATTERN</span> can have regular expression symbols also, to further fine tune the search e.g.,</span><span style="color: #000000;"> grep &#8217;^PATTERN$&#8217;  (line starting and ending with PATTERN and having nothing else). </span></li>
<li>Even exec could have done the same thing as xargs but latter is more efficient.
<pre class="brush:bash">find /path -name "file.*" -exec grep "PATTERN" {} \;</pre>
</li>
</ul>
<p>Examples,</p>
<p>To exclude some directory from search we can add <span style="color: #4c4c4c;">grep -v</span>, e.g.,</p>
<pre class="brush:bash">find . -iname "*.txt" -print0|grep -v /skip_dir/|xargs -0 grep "PATTERN"</pre>
<p>Files under directory <span style="color: #4c4c4c;">/skip_dir/</span> will not be searched now. A dot after find tells to start from present working directory</p>
<p>The output can be captured into some file (say output.txt), e.g.,</p>
<pre class="brush:bash">find . -iname  "file.*" -print0 | xargs -0 grep "PATTERN"&gt;output.txt</pre>
<p>Or else, if you want to mail this content to some user on this UNIX server, use this</p>
<pre class="brush:bash">find . -iname "file.*" -print0|xargs -0 grep "PTRN"|mail -s "Subject" userid@server</pre>
<p>If the file names have a space in them, then consider double quoting them before piping them to another command,</p>
<pre class="brush:bash">find . -iname "file.*"| sed 's/.*/"&amp;"/'| xargs ls -l &gt; outputfile.txt</pre>
<p>A useful example could be to find error_log files created by PHP (parsing errors), on a web server, under various directories.</p>
<pre class="brush:bash">find . -iname "error_log"| sed 's/.*/"&amp;"/'| xargs ls -l &gt; outputfile.txt</pre>
<p>or</p>
<pre class="brush:bash">find . -iname "error_log" -print0 | xargs -0 ls -l &gt; outputfile.txt</pre>
<p>Send a mail with this output in mail body,</p>
<pre class="brush:bash">find . -size +500k -iname "error_log"|sed 's/.*/"&amp;"/'|xargs ls -l|mail -s "Error files" userid@server</pre>
<p>This would mail you error_log files having size greater than 500KB. Though sed (special editor), to handle spaces, might not be having great importance here but it&#8217;s better to keep it for robustness of the command.</p>
<p>I have written a small shell script which does this job for me. Review or download it <a title="shell script to mail files found" href="http://www.expertsguide.info/download/check-files-in-shell-script.sh" target="_blank">here</a>. You are free to use it, in case you like it   <img src='http://www.expertsguide.info/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Using cron job you can run this at regular intervals., e.g.,</p>
<pre class="brush:bash">0 7 * * * root above_command</pre>
<p>This would email every day at 0700 hrs to the userid we specify in userid@server</p>
<p>Note: crontab file needs to be updated with the above command. Check if you have access to cron on your server. Also make sure you type and save the above command in UNIX context and not in DOS contex.</p>
<p>If the file names have a space in them, then consider double quoting them before doing anything else.</p>
<p>Keep checking <a title="expertsguide.info" href="http://www.expertsguide.info/" target="_blank">this article</a> for more updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/find-files-having-some-pattern-using-grep-in-unix/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>How to get elements from one array but not in another array</title>
		<link>http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/</link>
		<comments>http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 17:48:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=117</guid>
		<description><![CDATA[<p>How to get elements from one array but not in another array.</p>
<p>Or, in other words, how to get elements from one array minus elements from another array.</p>
<p>The task can be simplified and made efficient (less loops and less iterations) by creating a hash (associative array) from one array elements and then matching all the elements of <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/">How to get elements from one array but not in another array</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/usefull-php-array-functions/' rel='bookmark' title='Permanent Link: Usefull PHP array functions'>Usefull PHP array functions</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/' rel='bookmark' title='Permanent Link: How to access elements having some Class using Javascript?'>How to access elements having some Class using Javascript?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How to get elements from one array but not in another array.</p>
<p>Or, in other words, how to get elements from one array minus elements from another array.</p>
<p>The task can be simplified and made efficient (less loops and less iterations) by creating a hash (associative array) from one array elements and then matching all the elements of the other array one by one.  Example,</p>
<pre  class="brush:pl">#!/usr/bin/perl -w

@content = (1,2,3,4,5,6,7,8,9,'a','b','c','d','e');
@alphabets = ('a','b','c','d','e','f','g','h');

# create a hash with elements of @alphabets as keys and assign them a value 1
%alpha_hash =();
foreach my $alpha (@alphabets)
{
   $alpha_hash{$alpha} = 1;
}

foreach $elem (@content)
{
    unless ($alpha_hash{$elem}) # it's not in %alpha_hash, so this is what we need
    {     
        print $elem."\n";          #it is the one not present in $alphabets 
    }
}</pre>
<p> </p>
<p>Instead of printing the $elem we can store it in some array, suppose @result, then this array can be visualized to be subtraction of the two.</p>
<p>@result = @content &#8211; @alphabets</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/usefull-php-array-functions/' rel='bookmark' title='Permanent Link: Usefull PHP array functions'>Usefull PHP array functions</a></li>
<li><a href='http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/' rel='bookmark' title='Permanent Link: How to access elements having some Class using Javascript?'>How to access elements having some Class using Javascript?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/how-to-get-elements-from-one-array-but-not-in-another-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to access elements having some Class using Javascript?</title>
		<link>http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/</link>
		<comments>http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 15:26:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=114</guid>
		<description><![CDATA[<p>How to manipulate objects of all tags (suppose div) having some class name?</p>
<p>It can be achieved by first fetching all the div tags (or whichever you want) using function getElementsByTagName()
and then check their class name using another function className().  
It gives us more flexibility apart from getElementsByID() and getElementsByName().</p>

&#60;head&#62;
&#60;script type="text/javascript"&#62;
var allDivs = new Array();

// pass parameter "classval" the classname <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/">How to access elements having some Class using Javascript?</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/' rel='bookmark' title='Permanent Link: How to show or hide text using javascript?'>How to show or hide text using javascript?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/' rel='bookmark' title='Permanent Link: Access Form objects in case of multiple forms'>Access Form objects in case of multiple forms</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>How to manipulate objects of all tags (suppose div) having some class name?</p>
<p>It can be achieved by first fetching all the div tags (or whichever you want) using function getElementsByTagName()<br />
and then check their class name using another function className().  <br />
It gives us more flexibility apart from getElementsByID() and getElementsByName().</p>
<pre class="brush:js">
&lt;head&gt;
&lt;script type="text/javascript"&gt;
var allDivs = new Array();

// pass parameter "classval" the classname you want to manipulate
function getElementsByClass(classval)
{
  //Populate the array with all the div tags in the document
  allDivs = document.getElementsByTagName('div');

  for (var i=0; i&lt;allDivs.length; i++)
  {
    var obj = allDivs[i];
    //if allDivs[i].className is null it will not go to second part of the if condition
    if ( (obj.className) &amp;&amp; (obj.className == classval) )
    {     
      //do whatever you wish to this class
      if (obj.style.display == "none")    //check if already hidden, if yes make it appear
           obj.style.display = "";
      else
           obj.style.display = "none";    //if already appearing then hide here   
    }
  }
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;a href="#" onclick="javascript:getElementsByClass('myclass') ; return false;"&gt;Click here&lt;/a&gt;
&lt;div&gt;
&lt;div class='myclass'&gt;PHP&lt;/div&gt;
&lt;div class='myclass'&gt;Javascript&lt;/div&gt;
&lt;div class='myclass'&gt;Perl&lt;/div&gt;
&lt;div class='myclass'&gt;AJAX&lt;/div&gt;
&lt;div class='myclass'&gt;HTML&lt;/div&gt;
&lt;div class='myclass'&gt;MySQL&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
</pre>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/' rel='bookmark' title='Permanent Link: How to show or hide text using javascript?'>How to show or hide text using javascript?</a></li>
<li><a href='http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/' rel='bookmark' title='Permanent Link: Access Form objects in case of multiple forms'>Access Form objects in case of multiple forms</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/how-to-access-all-tags-having-some-class-using-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to show or hide text using javascript?</title>
		<link>http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/</link>
		<comments>http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 04:30:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=105</guid>
		<description><![CDATA[&#60;head&#62;
&#60;script&#62;
function showhide(id)
{
    if (document.getElementById)
    {
        obj = document.getElementById(id);
        if (obj.style.display == "none")    //check if already hidden, if yes make it appear
             <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/">How to show or hide text using javascript?</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/' rel='bookmark' title='Permanent Link: Access Form objects in case of multiple forms'>Access Form objects in case of multiple forms</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<pre class="brush:js">&lt;head&gt;
&lt;script&gt;
function showhide(id)
{
    if (document.getElementById)
    {
        obj = document.getElementById(id);
        if (obj.style.display == "none")    //check if already hidden, if yes make it appear
             obj.style.display = "";
        else
             obj.style.display = "none";    //if already appearing then hide here
    }
}
  &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="texthide"&gt;
Your text to dispay and hide goes here&lt;/div&gt;
&lt;a href="#" onclick="showhide('texthide'); return(false);"&gt;show/hide&lt;/a&gt;
&lt;/body&gt;</pre>
<p>Demo html page to <a href="http://www.expertsguide.info/download/show_hide_text.html">show/hide text using javascript</a>.</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/' rel='bookmark' title='Permanent Link: Access Form objects in case of multiple forms'>Access Form objects in case of multiple forms</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/how-to-show-or-hide-text-using-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to remove last comma from a string in PHP?</title>
		<link>http://www.expertsguide.info/2010/07/how-to-remove-last-comma-from-a-string-in-php/</link>
		<comments>http://www.expertsguide.info/2010/07/how-to-remove-last-comma-from-a-string-in-php/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 17:06:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=100</guid>
		<description><![CDATA[<p>To remove/trim the last/trailing or first/heading comma from a string, one should first confirm that the last character of the string is comma itself and nothing else. This would make the code foolproof and prevent accidental removal of characters other than comma.</p>
<p>A few methods are described here and listed in the order of increasing execution time <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/how-to-remove-last-comma-from-a-string-in-php/">How to remove last comma from a string in PHP?</a></span>


Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-create-a-random-string-in-php/' rel='bookmark' title='Permanent Link: How to create a random string in PHP'>How to create a random string in PHP</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>To remove/trim the last/trailing or first/heading comma from a string, one should first confirm that the last character of the string is comma itself and nothing else. This would make the code foolproof and prevent accidental removal of characters other than comma.</p>
<p>A few methods are described here and listed in the order of increasing execution time (faster listed first),</p>
<pre class="brush:php">$str = (substr($str,-1) == ',') ? substr($str, 0, -1) : $str;</pre>
<p>or</p>
<pre class="brush:php">$str = (substr($str,-1) == ',') ? substr_replace($str, '', -1) : $str;</pre>
<p>or, to remove all trailing commas</p>
<pre class="brush:php">$str = rtrim($str, ',');
//this removes all of the trailing commas eg 1,2,3,,,, =&gt; 1,2,3
//no need of condition check for last comma with rtrim()</pre>
<p>or</p>
<pre class="brush:php">$str = preg_replace("/,*$/", '', $str);
//RegEx engine overhead</pre>
<p>Similarly, to remove first comma (or any other character) from a string you can use this,</p>
<pre class="brush:php">$str = ($str[0] == ',') ? substr($str, 1) : $str;</pre>
<p>or</p>
<pre class="brush:php">$str = ($str[0] == ',') ? substr_replace($str, '',0,1) : $str;</pre>
<p>or, to remove all heading commas</p>
<pre class="brush:php">$str = ltrim($str, ',');
//this removes all of the trailing commas eg ,,,,,1,2,3 =&gt; 1,2,3
//no need of condition check for last comma with ltrim()</pre>
<p>or</p>
<pre class="brush:php">$str = preg_replace("/^,*/", '', $str);
//RegEx engine overhead</pre>
<p>Now the question arises, why to use above methods when ltrim() and rtrim() are already there? The answer is to use methods which are fastest (or at-least faster than others) in our PHP programs.</p>


<p>Related posts:<ol><li><a href='http://www.expertsguide.info/2010/07/how-to-create-a-random-string-in-php/' rel='bookmark' title='Permanent Link: How to create a random string in PHP'>How to create a random string in PHP</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/how-to-remove-last-comma-from-a-string-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>how to set or change a default printer on windows?</title>
		<link>http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/</link>
		<comments>http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 08:21:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=88</guid>
		<description><![CDATA[<p>How to set or change the Default Printer on windows?</p>
<p>To change the default printer to another printer connected to your computer, on Windows XP, follow below steps,</p>

 Click on the Start menu and then click on Printers and Faxes.
<p><p class="wp-caption-text">how-to-set-default-printer-1</p>
 A window which shows the icons of all the installed printers should appear. Right click on <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/">how to set or change a default printer on windows?</a></span>]]></description>
			<content:encoded><![CDATA[<p><strong>How to set or change the Default Printer on windows?</strong></p>
<p>To change the default printer to another printer connected to your computer, on Windows XP, follow below steps,</p>
<ul>
<li> Click on the Start menu and then click on Printers and Faxes.
<p><div id="attachment_91" class="wp-caption alignnone" style="width: 310px"><a href="http://www.expertsguide.info/wp-content/uploads/2010/07/how-to-set-default-printer-1.jpg"><img class="size-medium wp-image-91" title="how-to-set-default-printer-1" src="http://www.expertsguide.info/wp-content/uploads/2010/07/how-to-set-default-printer-1-300x213.jpg" alt="how-to-set-default-printer-1" width="300" height="213" /></a><p class="wp-caption-text">how-to-set-default-printer-1</p></div></li>
<li> A window which shows the icons of all the installed printers should appear. Right click on the desired printer icon. A menu should appear.
<p><div id="attachment_92" class="wp-caption alignnone" style="width: 213px"><a href="http://www.expertsguide.info/wp-content/uploads/2010/07/change-default-printer.jpg"><img class="size-medium wp-image-92" title="change-default-printer" src="http://www.expertsguide.info/wp-content/uploads/2010/07/change-default-printer-203x300.jpg" alt="change-default-printer" width="203" height="300" /></a><p class="wp-caption-text">change-default-printer</p></div></li>
<li> Select (Click) on “Set as Default”.</li>
</ul>
<p>That’s it!  <img src='http://www.expertsguide.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To confirm, right click on the printer icon again, a check mark before “Set as Default” should be there.</p>
<p>Even after setting a printer as the default, you can still print from other installed printers. The Print dialog box offers you a selection each time you print.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/how-to-set-or-change-a-default-printer-on-window/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to know if a file exists on the web or not, in PHP?</title>
		<link>http://www.expertsguide.info/2010/07/how-to-know-if-file-exists-on-web/</link>
		<comments>http://www.expertsguide.info/2010/07/how-to-know-if-file-exists-on-web/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 19:03:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=57</guid>
		<description><![CDATA[<p>I have listed a few methods in PHP to check the existence of a file on the web.</p>
&#60;?php
$fileURL = "http://www.some-domain.com/image.jpg";
echo "Checking the existence of $fileURL&#60;br&#62;";
?&#62;
<p>Method 1:</p>

&#60;?php
$a = microtime(true);                                    //start time in microseconds of 1st method
echo date("d/m/y : H:i:s", time()), " ",$a, "&#60;br&#62;";
get_http_response_code($fileURL);      //fast but not fool proof
echo "&#60;br&#62;";
$b = microtime(true);                                   //start time in microseconds of 2nd <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/how-to-know-if-file-exists-on-web/">How to know if a file exists on the web or not, in PHP?</a></span>]]></description>
			<content:encoded><![CDATA[<p>I have listed a few methods in PHP to check the existence of a file on the web.</p>
<pre class="brush:php">&lt;?php
$fileURL = "http://www.some-domain.com/image.jpg";
echo "Checking the existence of $fileURL&lt;br&gt;";
?&gt;</pre>
<p><strong>Method 1:</strong></p>
<pre class="brush:php">
&lt;?php
$a = microtime(true);                                    //start time in microseconds of 1st method
echo date("d/m/y : H:i:s", time()), " ",$a, "&lt;br&gt;";
get_http_response_code($fileURL);      //fast but not fool proof
echo "&lt;br&gt;";
$b = microtime(true);                                   //start time in microseconds of 2nd method
echo date("d/m/y : H:i:s", time()), " ", $b, "&lt;br&gt;";
echo "difference = ",$b-$a,"&lt;br&gt;";           //difference between 2nd and 1st
?&gt;
</pre>
<p><strong>Method 2:</strong></p>
<pre class="brush:php">
&lt;?php
isPartOfString($fileURL);
echo "&lt;br&gt;";
$c = microtime(true);                                  //start time in microseconds of 3rd method
echo date("d/m/y : H:i:s", time()), " ", $c, "&lt;br&gt;";
echo "difference = ",$c-$b,"&lt;br&gt;";         //difference between 3rd and 2nd
?&gt;</pre>
<p><strong>Method 3:</strong></p>
<pre class="brush:php">
&lt;?php
matchCode($fileURL);
echo "&lt;br&gt;";
$d = microtime(true);
echo date("d/m/y : H:i:s", time()), " ", $d, "&lt;br&gt;";
echo "difference = ",$d-$c,"&lt;br&gt;";
?&gt;</pre>
<p><strong>Method 4:</strong></p>
<pre class="brush:php">
&lt;?php
check_url($fileURL);
echo "&lt;br&gt;";
$e = microtime(true);
echo date("d/m/y : H:i:s", time()), " ", $e, "&lt;br&gt;";
echo "difference = ",$e-$d,"&lt;br&gt;";
?&gt;</pre>
<p><strong>Method 5:</strong></p>
<pre class="brush:php">
&lt;?php
http_file_exists($fileURL);
$f = microtime(true);
echo "difference = ",$f-$e,"
";
?&gt;
</pre>
<pre class="brush:php">
&lt;?php
function isPartOfString($fileURL)
{
   $getHeaders = @get_headers($fileURL);
   $str = $getHeaders[0];
   // 200 is the response code in the very first line of the headers when some file is found.
   // 3rd param starts search after HTTP/1
   $pos = strpos($str, ' 200 ', 5);   // Note the space before and after 200

   // Note: The !== operator should be used below.
   // Using != would not work as expected some times, e.g,
   // if the position of second param in the $str is 0 then statement (0 != false) evaluates
  //to false, though it was found....so take care of context also while forming conditions

   if ($pos !== false) {
   // now we can be sure that the func strpos returned something not in boolean context
      //returned pos is irrestive of offset
      if($pos &gt; 5)
      {
         echo "File found";
      }
   }
   else {
      //echo "The string '$findme' was not found in the string '$mystring'";
      echo "File not found";
   }
}
?&gt;</pre>
<pre class="brush:php">&lt;?php
function matchCode($theURL)
{
   $headers = get_headers($theURL);
   //this function uses regular expression engine, so might be a bit slow
   if (preg_match("/\s200\s/", $headers[0])) {
      echo "File found";
   }
   else  {
      echo "File not found";
     }
}
?&gt;</pre>
<pre class="brush:php">&lt;?php
function get_http_response_code($theURL) {
   $headers = get_headers($theURL);

   //this works only when position of the response code (200) dosn't alter in future
   if (substr($headers[0], 9, 3) == 200) 
   echo "File found";
   else
   echo "File not found";
}
?&gt;</pre>
<pre class="brush:php">&lt;?php
function check_url($url) {
   $c = curl_init();
   curl_setopt($c, CURLOPT_URL, $url);
   curl_setopt($c, CURLOPT_HEADER, 1); // get the header
   curl_setopt($c, CURLOPT_NOBODY, 1); // body not required
   curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // get response as a string from curl_exec, not echo it
   curl_setopt($c, CURLOPT_FRESH_CONNECT, 1); // don't use a cached version of the url
   if (!curl_exec($c)) {
      return false;
   }

   $httpcode = curl_getinfo($c, CURLINFO_HTTP_CODE);
   if($httpcode === 200)   // not &lt;400
   {
       echo "File found $httpcode &lt;br&gt;";
   }
   else
   {
        echo "File not found&lt;br&gt;";
   }
   #return ($httpcode &lt; 400);
}
?&gt;</pre>
<pre class="brush:php">
&lt;?php
function http_file_exists($url)
{
   $f = @fopen($url,"r"); //supress warnings by @
   if($f)
   {
      fclose($f);
      echo "File found ";
      return true;
   }
   echo "File not found ";
   return false;
}
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/how-to-know-if-file-exists-on-web/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Access Form objects in case of multiple forms</title>
		<link>http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/</link>
		<comments>http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 18:47:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=54</guid>
		<description><![CDATA[How to access form objects in case of multiple forms, using JavaScript?
<p>Assume, we have a form with the id &#8220;myform&#8221;, then form can be accessed  by:</p>
var oForm = document.getElementById('myform');
<p>This method can only be used only when the &#60;form&#62; tag has an id attribute.</p>
<p>Another way to do it without id attribute set to form tag  <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/">Access Form objects in case of multiple forms</a></span>]]></description>
			<content:encoded><![CDATA[<h3><span style="color: #888888;">How to access form objects in case of multiple forms, using JavaScript?</span></h3>
<p>Assume, we have a form with the id &#8220;myform&#8221;, then form can be accessed  by:</p>
<pre class="brush:js">var oForm = document.getElementById('myform');</pre>
<p>This method can only be used only when the <code>&lt;form&gt;</code> tag has an <code>id</code> attribute.</p>
<p>Another way to do it without <code>id</code> attribute set to form tag  is, by using <code>this</code> keyword. Get a reference to the form object,  through the <code>this.form</code> property (even if there are multiple forms on  the page).</p>
<p>Another way is to use the <em>document</em> object&#8217;s  <code>forms</code> collection. The <code>forms</code> collection is a Javascript  array that holds references to all the forms in a web page. Each form reference  can be accessed either by its index in this array or by its <em>name</em> attribute.</p>
<p>Let us look at each of these methods of accessing multiple  forms in details.</p>
<h3><span style="color: #888888;">How to access multiple Forms through Javascript using the <em>this.form</em>property?</span> </h3>
<p>Pass <code>this.form</code> to the onClick event handler of a form button.<br />
Example,</p>
<pre class="brush:js">&lt;form name ="myform"  action="#"&gt;
Name: &lt;input type="text" name="myname"  size="50"&gt;
Email: &lt;/label&gt;&lt;input type="text" name="email"  size="50"&gt;
Phone: &lt;input type="text" name="phone"  size="50"&gt;
&lt;input type="button" name="go" value="Go"  onclick="showElements(this.form);"&gt;
&lt;/form&gt; </pre>
<p>Here, <code>this</code> refers to the button object, and  <code>this.form</code> references the form object. This form object can be used  in the <code>showElements</code> function to access the form and all its  elements.</p>
<h3><span style="color: #888888;">How to access multiple Forms using the document object&#8217;s <em>forms</em> collection</span></h3>
<p>The document object of a page has an array <code>forms</code> which holds  references to all the form objects on that page. We can get references to  individual forms by using the index or names. Index begins at 0.</p>
<p>For eg., if we have two forms with names as &#8220;firstform&#8221; and &#8220;secondform&#8221;  respectively, we can access the form named &#8220;firstform&#8221; in the following two  ways:</p>
<pre class="brush:js">var oForm = document.forms[0];
//OR
var oForm =  document.forms["firstform"]; </pre>
<p>We could also use the shorthand notation: document.formname:</p>
<pre class="brush:js">var  oForm = document.firstform; </pre>
<p><span style="color: red;">Note: The shorthand notation is deprecated, and is either not  supported in recent versions of Firefox or is buggy and unreliable.</span></p>
<p>It is also preferable to use the form&#8217;s name attribute instead of the index,  as it is less likely for the name of the forms on the page to change, and more  likely for their sequential position in the code to change.</p>
<p>Every form field of a form is contained in the form&#8217;s <code>elements</code> collection which is a javascript array similar to the document object&#8217;s  <code>forms</code> collection.</p>
<p>To access the text input field named &#8220;tags_list&#8221; of the form named  &#8220;submit_bookmark&#8221;, we can use one of the following methods:</p>
<pre class="brush:js">var  oForm = document.forms["submit_bookmark"];
var oTagsList = oForm.elements[2];
//OR
var oTagsList = oForm.elements["tags_list"]; 

//Get the value of the input element,
var tags  = oTagsList.value; </pre>
<p>As a further example, let us say that we had to copy the value of an element  in one form into an element in another form.</p>
<p>We could implement this by passing the names of the two forms as well as the  names of the source and target elements to a javascript function:</p>
<pre class="brush:js">&lt;a href="#" onClick=" javascript:  copyFormElementToElementOfDifferentForm('submit_article', 'submit_bookmark',  'site_cat', 'tags_list');"&gt; Copy site_cat element value of the first form to  the input field named "tags_list" of the second form&lt;/a&gt;
&lt;script&gt;
var oForm1 =  document.forms[oForm1Name];
var oForm2 =  document.forms[oForm2Name];
var oForm1Element =  oForm1[oForm1ElementName];
var oForm2Element =  oForm2[oForm2ElementName];
if(oForm2Element.value == '')  {
oForm2Element.value += oForm1Element.value;
} else  {
oForm2Element.value += ', ' +  oForm1Element.value;
}
&lt;/script&gt;</pre>
<p>Here, we first acquire references to form objects using their names. We then  acquire references to the source and target elements. Then, copy the value of  the source element to the target element.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/access-form-objects-in-case-of-multiple-forms/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to create a random string in PHP</title>
		<link>http://www.expertsguide.info/2010/07/how-to-create-a-random-string-in-php/</link>
		<comments>http://www.expertsguide.info/2010/07/how-to-create-a-random-string-in-php/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 18:19:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.expertsguide.info/?p=35</guid>
		<description><![CDATA[<p>A random string with length specified as a parameter ($sLength) and having allowable characters in another parameter ($a).</p>
&#60;?php
$s = ""; //random string
$sLength = 35; //random string length (you can put any number, you like your string to be in length)

//allowable chars in the wanted random string (add other chars but avoid chars having special meanings to <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/how-to-create-a-random-string-in-php/">How to create a random string in PHP</a></span>]]></description>
			<content:encoded><![CDATA[<p>A random string with length specified as a parameter ($sLength) and having allowable characters in another parameter ($a).</p>
<pre class="brush:php">&lt;?php
$s = ""; //random string
$sLength = 35; //random string length (you can put any number, you like your string to be in length)

//allowable chars in the wanted random string (add other chars but avoid chars having special meanings to OS)
$a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
for($i = 0, $z = strlen($a)-1; $i != $sLength; $i++)
{
     $x = rand(0,$z);
     $s .= $a{$x};
}
echo $s;
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/how-to-create-a-random-string-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alter Regular Expression Match Position in Perl</title>
		<link>http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/</link>
		<comments>http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 11:49:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[recursive regular expression]]></category>

		<guid isPermaLink="false">http://expertsguide.info/?p=23</guid>
		<description><![CDATA[How to alter the regular expression match position?
<p>The perl function pos() retrieves or modifies the position where the next match attempt is going to begin. The beginning of a string (first character) has a position zero. This position can be modified by using the function as the left side of an assignment, e.g.,     pos($string) = 123;.</p>
<p>An <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/">Alter Regular Expression Match Position in Perl</a></span>]]></description>
			<content:encoded><![CDATA[<h3><span style="color: #888888;">How to alter the regular expression match position?</span></h3>
<p>The perl function <strong><tt>pos()</tt></strong> retrieves or modifies the position where the next match attempt is going to begin. The beginning of a string (first character) has a position zero. This position can be modified by using the function as the left side of an assignment, e.g.,     <tt>pos($string) = 123;</tt>.</p>
<p>An example of altering position can be,</p>
<pre class="brush:pl">while ($string =~ m/regex/g)  {
print "Found .  Next attempt would be at character " . pos($string)+1 . "\n";

#pos($string)=5;   #this would change the position of the reg ex match at 5.
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/alter-regular-expression-match-position-in-perl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Usefull PHP array functions</title>
		<link>http://www.expertsguide.info/2010/07/usefull-php-array-functions/</link>
		<comments>http://www.expertsguide.info/2010/07/usefull-php-array-functions/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 15:53:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://expertsguide.info/?p=1</guid>
		<description><![CDATA[How to check if a value exists in array or not  in PHP?
<p>PHP function in_array() checks if a value exists in an array in a case-sensitive manner and returns boolean result.
e.g.,</p>
<p>&#60;?php
$os = array(&#8220;Mac&#8221;, &#8220;NT&#8221;, &#8220;Unix&#8221;, &#8220;Linux&#8221;);
if (in_array(&#8220;Unix&#8221;, $os)) {
echo &#8220;Got Unix&#8221;;
}
?&#62;</p>
How to check if a key/index exists in array or not  in PHP?
<p>PHP function <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.expertsguide.info/2010/07/usefull-php-array-functions/">Usefull PHP array functions</a></span>]]></description>
			<content:encoded><![CDATA[<h3><span style="color: #888888;"><strong>How to check if a value exists in array or not  in PHP?</strong></span></h3>
<p>PHP function in_array() checks if a value exists in an array in a case-sensitive manner and returns boolean result.<br />
e.g.,</p>
<p>&lt;?php<br />
$os = array(&#8220;Mac&#8221;, &#8220;NT&#8221;, &#8220;Unix&#8221;, &#8220;Linux&#8221;);<br />
if (in_array(&#8220;Unix&#8221;, $os)) {<br />
echo &#8220;Got Unix&#8221;;<br />
}<br />
?&gt;</p>
<h3><span style="color: #888888;"><strong>How to check if a key/index exists in array or not  in PHP?</strong></span></h3>
<p>PHP function array_key_exists() checks if the given key or index exists in the array and returns boolean result<br />
e.g.,</p>
<p>&lt;?php<br />
$search_array = array(&#8216;first&#8217; =&gt; 1, &#8216;second&#8217; =&gt; 4);<br />
if (array_key_exists(&#8216;first&#8217;, $search_array)) {<br />
echo &#8220;The &#8216;first&#8217; element is in the array&#8221;;<br />
}<br />
?&gt;</p>
<h3><span style="color: #888888;"><strong>How to get all keys in an array in PHP?</strong></span></h3>
<p>PHP function array_keys() returns all the keys of an array<br />
eg.,</p>
<p>In associative array/hash reference,<br />
&lt;?php<br />
$array = array(0 =&gt; 100, &#8220;color&#8221; =&gt; &#8220;red&#8221;);<br />
print_r(array_keys($array));<br />
?&gt;</p>
<p>It returns,<br />
Array (<br />
[0] =&gt; 0<br />
[1] =&gt; color<br />
)</p>
<p>In array reference,<br />
&lt;?php<br />
$array = array(&#8220;blue&#8221;, &#8220;red&#8221;, &#8220;green&#8221;, &#8220;blue&#8221;, &#8220;blue&#8221;);<br />
print_r(array_keys($array, &#8220;blue&#8221;));  //all indexes where value is blue<br />
?&gt;</p>
<p>It returns,<br />
Array (<br />
[0] =&gt; 0<br />
[1] =&gt; 3<br />
[2] =&gt; 4<br />
)</p>
<h3><span style="color: #888888;"><strong>How to get all values in an array in PHP?</strong></span></h3>
<p>PHP function array_values() returns all the values from the input array and indexes numerically the array.<br />
eg.,</p>
<p>&lt;?php<br />
$array = array(&#8220;size&#8221; =&gt; &#8220;XL&#8221;, &#8220;color&#8221; =&gt; &#8220;gold&#8221;);<br />
print_r(array_values($array));<br />
?&gt;</p>
<p>It returns,<br />
Array<br />
(<br />
[0] =&gt; XL<br />
[1] =&gt; gold<br />
)</p>
<p><span style="color: #888888;"><strong>Array loops,</strong></span></p>
<p>Apart from well known &#8220;for&#8221; and &#8220;foreach&#8221; loops, there another way to loop through the indexed/associative array,<br />
&lt;?php</p>
<p>$array = array(&#8220;value1&#8243;,&#8221;value2&#8243;,&#8221;value3&#8243;);</p>
<p>for(reset($array),current($array),next($array){<br />
echo(&#8220;Element &#8220;.key($array).&#8221; contains &#8220;.current($array).&#8221;&lt;br/&gt;&#8221;;<br />
}</p>
<p>//is the equivalent of&#8230;</p>
<p>for($i=0;$i&lt;count($array);$i++){<br />
echo(&#8220;Element $i contains $array[$i]&lt;br/&gt;&#8221;);<br />
}<br />
//It&#8217;s use is probably to save on the no. of variables used.</p>
<p>?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expertsguide.info/2010/07/usefull-php-array-functions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 80/503 queries in 0.037 seconds using disk
Object Caching 7801/8055 objects using disk

Served from: www.expertsguide.info @ 2012-02-23 01:58:12 -->
