Thursday, July 19, 2012

Email validation using Regular Expression

Following code shows how to validate email in php.

<?php // chek email validation
if (!preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',$_POST['email']))
{
echo "invalid Email Address";
}
?>

Detect url contains query string ?

parse_url function is used to break the url components
This function parses a URL and returns an associative array containing any of the various components of the URL that are present.
  • scheme - e.g. http
  • host
  • port
  • user
  • pass
  • path
  • query - after the question mark ?
  • fragment - after the hashmark #


The following code reads url query string and convert into array.

<?php
$queries= parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY);

 // splits url query string into array
$queries_elements = split('&', $queries);
//converts to array
for($i = 0; $i != sizeof($queries_elements); $i++)
    {
    $queries = split('=', $queries_elements[$i]);
    //assigns to new array
    $params[$queries[0]]=$queries[1];
    }
var_dump($params);

?> 

More examples 
echo parse_url('http://example.com?mode=edit&id=34', PHP_URL_QUERY);
Output : 'mode=edit&id=34'
echo parse_url('http://example.com?mode=edit&id=34#user', PHP_URL_FRAGMENT)
Output : 'user'
echo parse_url('http://example.com', PHP_URL_SCHEME);
Output : 'http'
echo parse_url('http://example.com?mode=edit&id=34#user', PHP_URL_HOST);
Output : 'example.com'
echo parse_url('http://example.com:88?id=34', PHP_URL_PORT);
Output : 88

Tuesday, January 3, 2012

PHP - php.ini explained

PHP.ini is very useful and it is a configuration file that is used to customize behavior of PHP at runtime. This enables easy administration in the way you administer Apache web server using configuration files. The Settings in which  upload directory, register global variables, display errors, log errors, max uploading size setting, maximum time to execute a script and other configurations is written in this file.

When PHP Server starts up it looks for PHP.ini file first to load various values for settings. If you made changes in PHP.ini then you need to restart your server to check the changes be effected.

The major configuration parameters in php.ini as follows

OptionDescription
short_open_tag=<On|Off>The short open tag <? instead of <?php.
If you run old applications, enable this; this may cause confusion if other language processors like XML, etc, are present.
output_buffering=<Off|Integer|On>Maximum output data buffer size before sending to client. On enables infinite buffer size (dangerous!). Best value: 4096.
zlib.output_compression=<Off|On>Enables/disables gzip compression of output.
max_execution_time=<Integer>Maximum script execution time (in seconds), set to 0 for CLI. Should be set after trial and error, though 30-60 seconds should be good for standard applications. A very large value is dangerous; a script can hog resources for a long time.
max_input_time=<Integer>Maximum time a script can spend parsing request data. Default is unlimited (-1) [hard-coded for CLI].
memory_limit=<size>Maximum memory a script may consume; size defaults to bytes, but modifiers like M, G can be applied, like 128 M. Keep it so that malicious scripts don’t hog all available memory. 128-256 M is sufficient.
error_reportingSets the type of errors reported to stdout, stderr or the error log. Default value: E_ALL & ~E_NOTICE. Production value: E_ALL & ~E_DEPRECATED. Development value: E_ALL | ~E_STRICT
display_errors=<Off|On|stderr>Displays errors to stdout or stderr. Stderr affects only CLI and CGI binaries.
include_path=<paths separated by colon>Colon-separated paths for PHP to search for files named in include, require, include_once or require_once.
file_uploads = <Off|On>Enables/disables file uploads.
upload_max_filesize=<size>Maximum file-size for file upload; takes modifiers like M, G, etc.
max_file_uploads=<Integer>Maximum number of files that can be uploaded in a single request.
allow_url_include=<Off|On>Inclusion of PHP files from URLs. This can pose a security threat; malicious files can be included from remote servers.
extension_dir=<path>Location to find PHP extensions.
extension=<filename>Tells PHP to load the extension named. filename takes full path to the extension, else it will be sought in extension_dir.

Saturday, December 31, 2011

What India searched in 2011


How the India Searched. What mattered in 2011? Zeitgeist sorted billions of Google searches to capture the year's 10 fastest-rising queries and the rest of the spirit of 2011.

Google announced their Zeitgeist of 2011. Google discloses the spirit through the aggregation of millions of users search queries and it takes it as hot trends in every day. Every Year Google releasing the whole year top searches list in raking wise as the name of Google Zeitgeist.

InIndia, Google published the 6 categories of searches such as Fast rising searches, Fast rising People, Top Searches, People, Movies and News.

The first 10 most searching keywords in 2011 are follows

NewsPeople
1. Ipl1. Katrina Kaif
2. World Cup 20112. Anna Hazare
3. Cbse Result 20113. Salman Khan
4. Diwali4. Poonam Pandey
5. Lokpal Bill5. Justin Bieber
6. Japan Earthquake6. Aishwarya Rai
7. Aadhar Card7. Sachin Tendulkar
8. Osama Bin Laden8. Kareena Kapoor
9. Pakistan9. Steve Jobs
10. F110. Priyanka Chopra
MoviesTop Searches
1. Bodyguard1. Facebook
2. Ra One2. Youtube
3. Harry Potter3. Gmail
4. Delhi Belly4. Yahoomail
5. Singham5. Google
6. Ready6. Yahoo
7. Mankatha7. Irctc
8. Transformers 38. Rediffmail
9. Dookudu9. Indian Railways
10. Zindagi Na Milegi Dobara10. Way2sms

Tuesday, December 20, 2011

Story behind famous brand names

Google 
Googol misspelled as google
A googol is equivalent to a 1 followed by 100 zeros. When Larry Page and Sean Anderson came up with the name, Sean misspelled it as Google when seeing if the domain was available. Another report claims that Andy Bechtolsheim, co-founder of Sun Microsystems and Google’s first investor, misspelled the name on his $100,000 investment check.


Microsoft 
Bill Gates named Microsoft from two words: “Microcomputer” and “Software”. In year 1975, Bill Gates wrote a letter to his colleague Paul Allen, he wrote as Micro-Soft. But in 1976 they registered the name Microsoft as a single name.

Cisco
Short for San Francisco where the company was founded.

Hotmail
Hotmail is based on HTML and the company wanted to give it a name that will sound like HTML and have the word “mail” at the end. They finally selected the name “HoTMaiL”, but later changed the word casing and made it “Hotmail”.

Adobe
Adobe is the name of a river. One of the founders of Adobe, John Nack, lives in Los Altas in California. This river runs behind his house. This is how Adobe got its name.

HP
Bill Hewlett and Dave Packard 
Named after their founders, Bill Hewlett and Dave Packard. They tossed a coin to determine if the company would be named Hewlett-Packard or Packard-Hewlett. Packard won the coin toss but chose to leave it as Hewlett-Packard.

Skype
Originally Sky-Peer-to Peer, then Skyper, and finally Skype.

Verizon
A combination of the words veritas, the Latin word for truth, and horizon, signifying forward-looking and visionary.

Visa
Dee Hock, Visa’s founder, believed that the word would be instantly recognizable by many languages and universally accepted by many countries.

Yahoo! –Coined by Jonathan Swift in his book Gulliver’s Travels, a yahoo (short for yahooligan) is a repulsive, filthy creature.

Thursday, December 15, 2011

Can you identify this


This is a hard disk made by IBM in 1956. Its Capacity just 5MB.



IBM 305 disk storage unit

In September 1956 IBM launched the 305 RAMAC, the  first SUPER COMPUTER with a hard disk drive (HDD). The HDD weighed over a tonne and stored 5 MB of data.



Introduced in 1956, the IBM 305 RAMAC (Random Access Memory Accounting System) was an electronic general purpose data processing machine that maintained business records on a real-time basis. The 305 RAMAC was one of the last vacuum tube systems designed by IBM.

System Unit

Tuesday, December 13, 2011

Bill Gates Arrested

Can you ever imagine today’s billionaire, world’s richest man and now greatest philanthropist person Bill Gates has gone to jail?

Bill Gates, Chairman and CEO of Microsoft (Retired), and the richest man in the world at over $50 Billion net worth, arrested in New Mexico 1977.



He was arrested for speeding in his Porsche car without a license and again in 1989 for suspicion of drunk driving.