Posts Tagged ‘Regular’

Search engine optimization-Add new content all the time

Tuesday, July 15th, 2008

Sites that have new content added on a regular basis are seen as more reliable than sites that rarely do. This also helps you to increase the amount of relevant content on your site, which also improves your rankings.

ABOUT CALCULATOR-GOOGLE

Tuesday, July 15th, 2008

You can use the regular search box to make certain calculations and conversions. Examples: 2+99= will get you 101; 2*2= will get you 4. To run conversions, use the following format: 100 miles = ? km or 100 pounds = ? kilos. Need to convert US dollars into Indian rupees? 1 USD = ? INR.

PHP:Validate URL (FTP, HTTP) using regular expression ( regex )

Monday, June 30th, 2008

<?php
/**
* valid_url - validates supplied url with a regular expression ( regex ).
*
* URL can be FTP, HTTP secure
* @param $url String
* @return true if the address is valid
* @author RAJI
*
*/
function valid_url( $url )
{
if ( !preg_match( ‘!^((ht|f)tps?://)?[a-zA-Z]{1}([w-]+.)+([w]{2,5})/?$!i’, $url ) )
{
return false;
} else
{
return true;
}
}
if ( valid_url( “http://blog.tryangled.com” ) )
{
echo “URL OK”;
} else
{
echo “Invalid URL.”;
}
?>

Regular Expressions for input validation?

Saturday, June 28th, 2008

It is always a good idea to try and avoid regular expressions, where possible and practical. There are functions in PHP which will do exactly what some regular expressions do, but faster. Take this example:

if(ereg(’[0123456789]‘, $number)) {
// Is integer
}else{
// Is not integer
}

It is much faster to do this instead:

if(ctype_digit($number)) {
// Is integer
}else{
// Is not integer
}

To test this, I used ereg(’[0123456789]‘, $number) 1,000,000 times, followed by using ctype_digit($number) 1,000,000 times. Here are the results:

Regular Expressions: 2.401 seconds
ctype_digit: 0.985 seconds
Time saved: 1.416 seconds; 58.98%