About ExpertsGuide.info

Rating 1.60 out of 5

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, . . . → Read More: About ExpertsGuide.info

CSS margin style property not working

Rating 3.00 out of 5

There’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.

For example, if there an unordered list tag above a paragraph tag. The list tag is assigned with the bottom margin of 20 pixels . . . → Read More: CSS margin style property not working

Inner Join example in MySQL

Rating 3.50 out of 5

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,

Table_1

product_id

product_name

1

Car

2

Truck

3

Scooter

4

Bicycle

Table_2

product_id

product_price

1

50000

2

60000

3

5000

4

1000

then to show the product names with their price, we can write an SQL statement (Inner Join) like this,

SELECT a.product_name, b.product_price FROM Table_1 a, Table_2 WHERE a.product_id=b.product_id;

This . . . → Read More: Inner Join example in MySQL

How to find all occurrences of a string in another string using Perl

Rating 3.00 out of 5

How to find all occurrences of a string in another string using 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 + . . . → Read More: How to find all occurrences of a string in another string using Perl

Compare Bing and Google results on same page

Rating 3.00 out of 5

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.

Try www.bing-vs-google.com

bing-vs-google

Interesting? . . . → Read More: Compare Bing and Google results on same page

Greedy Search in Perl Regular Expressions

Rating 2.33 out of 5

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.,

$var = ‘some_url?id=1&number=2&name=Peter&address=someaddress’;

In the above string if you only want to capture the value of “id” (i.e. 1) and you use this regex

$var =~ /\?(.*)=(.*)\&/ ;

it will not work as . . . → Read More: Greedy Search in Perl Regular Expressions

send mail using mail command in UNIX

Rating 2.00 out of 5

Sometimes we need to send e-mails from UNIX command-line itself. Sometimes we need to write a small script to do so. Here’s what we need to do for such tasks.

We can send mail in UNIX using “mail” command. Syntax is as follows,

mail -s “Subject” -c “any_cc_email_id” -b “any_bc_email_id” “comma_separated_To_email_id”

But the above syntax . . . → Read More: send mail using mail command in UNIX

Red ants in laptop

Rating 3.33 out of 5

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?

The answer is that . . . → Read More: Red ants in laptop

Difference between Optical Mouse and Laser Mouse

Rating 2.00 out of 5

Difference between an Optical Mouse and a Laser Mouse

Optical mouse and laser mouse are different varieties of digital mice which have overwhelmed ball rollers ones.

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 . . . → Read More: Difference between Optical Mouse and Laser Mouse

How to know if document exists on a URL in perl

Rating 3.00 out of 5

Pinging a server doesn’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,

use LWP::Simple;
$URL=’http://www.expertsguide.info/’;
if (head($URL))
{
print ‘$URL exists’ ;
}
else
{
   print ‘URL does not contain anything’;
}

head() function . . . → Read More: How to know if document exists on a URL in perl

How to know memory used by current running tasks on Windows

Rating 2.50 out of 5

Just like “ps -ef” on UNIX there’s a handy command (“tasklist”) on windows which shows all the tasks (processes) running currently and memory used by them.

If you open the command prompt on windows (Start->Run->cmd  and Press Enter), it opens a command prompt. Type “tasklist” and press enter. It gives a long table . . . → Read More: How to know memory used by current running tasks on Windows

Common mistakes and points to remember in MySQL

Rating 3.00 out of 5

Some common mistakes we often commit while coding in PHP to access MySQL DB (Database).

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 . . . → Read More: Common mistakes and points to remember in MySQL

How to increase file upload limit using .htaccess

Rating 3.00 out of 5

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. “.htaccess” file . . . → Read More: How to increase file upload limit using .htaccess

How to compare the execution time of PHP code blocks

Rating 3.67 out of 5

How to compare the execution time of PHP code blocks?

Sometimes we want to test our code for efficiency and execution time by comparing it with other code. Here’s how you can compare two code blocks in PHP and decide which one is faster (helps in optimization of code).

$str = ’1,2,3,4,’; . . . → Read More: How to compare the execution time of PHP code blocks

How to optimize PHP code

Rating 4.25 out of 5

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) “Loops” (for, foreach, while) are . . . → Read More: How to optimize PHP code

HTTP Authentication in URL not working in IE

Rating 2.00 out of 5

IE (Internet Explorer) doesn’t work with user names and passwords in Web site addresses URLs (HTTP/S).
Though, IE versions 3.0 to 6.0 support this.

The following URL syntax may not work in Internet Explorer or in Windows Explorer,
http(s)://username:password@mydomain.com

Reason:
Such URL syntax is used to automatically send username/password to a Web site which requires basic authentication.
A . . . → Read More: HTTP Authentication in URL not working in IE

Sanitize User Input with MySQL

Rating 3.00 out of 5

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.

Always protect your code and database from . . . → Read More: Sanitize User Input with MySQL

New Text Document on right click menu missing

Rating 3.00 out of 5

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 -> New ->”TXT document”.

If you have suffered the same, no worries, here’s the solution for Windows XP.

Put this registry entry into a plain text document and name . . . → Read More: New Text Document on right click menu missing

Stop indexing files in a directory using .htaccess

Rating 3.00 out of 5

How to stop indexing of files in a directory using .htaccess?

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’s a simple solution to this, put an index.html file showing a decent message . . . → Read More: Stop indexing files in a directory using .htaccess

Block robots from accessing webpages using .htaccess

Rating 4.00 out of 5

How to block

Use htaccess file.
this is run by server and ensured by the server that the rules written in it are enforced.

On the other hand, robots.txt file is just a guideline file. Robots are not bound to follow it.

To ensure denial of all requests for the restricted directory, put the following in . . . → Read More: Block robots from accessing webpages using .htaccess

Use .htaccess to rewrite/redirect requests

Rating 4.00 out of 5

How to redirect or rewrite URLs using .htaccess?

File, called as .htaccess, can be used to rewrite URLs apart from doing other stuffs like application handlers etc.

We can do some potent manipulations with our links, like,

Transforming long URL’s into short, easy to remember URLs
Transforming URLs having in-comprehensive query strings like “filename?id=carnivores&cat=animals” into  human readable URLs like “livingthings/animals/carnivores”
Redirect missing . . . → Read More: Use .htaccess to rewrite/redirect requests

Parse XML or HTML

Rating 2.50 out of 5

Here’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.

<?php
$xml = <<<EOT
<?xml version=”1.0″ encoding=”UTF-8″?>
<entry xmlns=”http://www.w3.org/2005/Atom” xmlns:other=”http://other.w3.org/other” >
        <id>uYG7-sPwjFg</id>
        <published>2009-05-17T18:29:31.000Z</published>
</entry>
EOT;
$doc = new DOMDocument;
$doc->loadXML($xml);
$xpath =  DOMXPath($doc);
$xpath->registerNamespace(‘atom’, “http://www.w3.org/2005/Atom”);

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

$entries = $xpath->evaluate($xpath_str);

print $entries->item(0)->nodeValue .”\n”;

?>

You . . . → Read More: Parse XML or HTML

A simple AJAX tutorial

Rating 2.00 out of 5

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.

Lets create a simple AJAX implemented webpage. and see how it works.

Create an . . . → Read More: A simple AJAX tutorial

How to send mail when Googlebot crawls a webpage of your website

Rating 4.00 out of 5

How to send an email, as soon as Googlebot crawls a webpage of your website, in PHP?

Many of us have always wished to get some kind of intimation as soon as Google (Googlebot to be specific) crawls our websites. Isn’t it?
Don’t know if there are any tools available for the same but what . . . → Read More: How to send mail when Googlebot crawls a webpage of your website

How to parse PHP in html pages

Rating 3.00 out of 5

How to parse PHP in web pages having extension as .html / .htm?

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.

Create a simple text file.  Put the following code in that . . . → Read More: How to parse PHP in html pages

Set time out while downloading files in PHP

Rating 3.00 out of 5

How to set a timeout while downloading a file from web in PHP?

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.

Method 1, using cURL timeout,

<?php
$url = ‘http://www.example.com’;
$text = content_from_curl($url);

function content_from_curl($url)
{
$content = false; . . . → Read More: Set time out while downloading files in PHP

CSS font-size property not working in Internet Explorer

Rating 3.00 out of 5

CSS (Cascading Style Sheete) font-size property does not work properly in Internet Explorer (IE) if spcified in this way,

font-size: small

or

font-size: medium

In mozilla firefox, it works fine.

Workaround:

Use em to specify the font size e.g.,

<style  type=”text/css”>
body {font-size: 0.75em;}
</style>

 

Inheritance can cause problems, for nested tags, when em or % sizing of the text is used. For example, if you . . . → Read More: CSS font-size property not working in Internet Explorer

Button tag inside anchor not working in IE

Rating 3.50 out of 5

HTML button tag might not work as expected when put inside anchor tags.

<a href=”http://www.expertsguide.info/”><button type=”button”>Click Me to go to Experts Guide</button></a>

I works well in Mozilla Firefox but in Internet Explorer (IE) nothing happens on clicking it.

Workaround:

Put some javascript event inside onclick event handler. Redirect (or open a new window) in javascript to required . . . → Read More: Button tag inside anchor not working in IE

Find all files having some pattern using grep in UNIX

Rating 3.67 out of 5

How to find all files under a directory, having a pattern, in their name or content,  in UNIX?

grep command can be used in conjunction with xargs to fetch filenames having some pattern in them.

find  /search_dir/ -iname  “*.*” -print0 | xargs -0 grep ”PATTERN”

where,
search_dir is the directory where search has to begin from
PATTERN is the . . . → Read More: Find all files having some pattern using grep in UNIX

How to get elements from one array but not in another array

Rating 3.00 out of 5

How to get elements from one array but not in another array.

Or, in other words, how to get elements from one array minus elements from another array.

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 . . . → Read More: How to get elements from one array but not in another array

How to access elements having some Class using Javascript?

Rating 3.67 out of 5

How to manipulate objects of all tags (suppose div) having some class name?

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().

<head>
<script type=”text/javascript”>
var allDivs = new Array();

// pass . . . → Read More: How to access elements having some Class using Javascript?

How to show or hide text using javascript?

Rating 3.00 out of 5

<head>
<script>
function showhide(id)
{
if (document.getElementById)
{
obj = document.getElementById(id);
if (obj.style.display == “none”) //check if already hidden, if yes make it appear
. . . → Read More: How to show or hide text using javascript?

How to remove last comma from a string in PHP?

Rating 3.50 out of 5

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.

A few methods are described here and listed in the order . . . → Read More: How to remove last comma from a string in PHP?

how to set or change a default printer on windows?

Rating 3.00 out of 5

How to set or change the Default Printer on windows?

To change the default printer to another printer connected to your computer, on Windows XP, follow below steps,

Click on the Start menu and then click on Printers and Faxes.

how-to-set-default-printer-1

A window which shows the icons of all the installed printers should . . . → Read More: how to set or change a default printer on windows?

How to know if a file exists on the web or not, in PHP?

Rating 3.50 out of 5

I have listed a few methods in PHP to check the existence of a file on the web.

<?php
$fileURL = “http://www.some-domain.com/image.jpg”;
echo “Checking the existence of $fileURL<br>”;
?>

Method 1:

<?php
$a = microtime(true);                                    //start time in microseconds of 1st method
echo date(“d/m/y : H:i:s”, time()), ” “,$a, “<br>”;
get_http_response_code($fileURL);      //fast but not fool proof
echo “<br>”;
$b = microtime(true);                                   //start time . . . → Read More: How to know if a file exists on the web or not, in PHP?

Access Form objects in case of multiple forms

Rating 4.00 out of 5

How to access form objects in case of multiple forms, using JavaScript?

Assume, we have a form with the id “myform”, then form can be accessed by:

var oForm = document.getElementById(‘myform’);

This method can only be used only when the <form> tag has an id attribute.

Another way to do it without id attribute set . . . → Read More: Access Form objects in case of multiple forms

How to create a random string in PHP

Rating 3.00 out of 5

A random string with length specified as a parameter ($sLength) and having allowable characters in another parameter ($a).

<?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 . . . → Read More: How to create a random string in PHP

Alter Regular Expression Match Position in Perl

Rating 4.00 out of 5

How to alter the regular expression match position?

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, . . . → Read More: Alter Regular Expression Match Position in Perl

Usefull PHP array functions

Rating 4.00 out of 5

How to check if a value exists in array or not in PHP?

PHP function in_array() checks if a value exists in an array in a case-sensitive manner and returns boolean result.
e.g.,

<?php
$os = array(“Mac”, “NT”, “Unix”, “Linux”);
if (in_array(“Unix”, $os)) {
echo “Got Unix”;
}
?>

How to check if a key/index exists in array or not . . . → Read More: Usefull PHP array functions