Search:

Categories



World population

<?php
$url = “http://www.census.gov/ipc/www/popclockworld.html“;
$fp = fopen($url, “r”);
$search = fread($fp, 32000);
fclose($fp);
$search = ereg(“<div id=\”worldnumber\”>(.*)</div><p></p>”, $search, $content);
echo “<h2>World Population</h2>”;
echo “<div align=\”center\”><br>$content[1]<br></div>”;
?>

Share

US population example

 

<?php
//the address with the figures, this may change in the future
$url = “http://www.census.gov/population/www/popclockus.html“;
$fp = fopen($url, “r”);
$search = fread($fp, 32000);
fclose($fp);
//the html that surrounds the figures we want, this may change
$search = ereg(“<div id=\”usnumber\”>(.*)</div></p>”, $search, $content);
echo “<h2>US Population</h2>”;
echo “<br>$content[1]<br>”;
?>

Share

Check the amount of characters in a string function

<?php
//check the amount of characters in a string function
Function CheckNoChars($strText)
{
//check for between 6 and 12 characters
if (eregi(“^.{6,12}$” , $strText))
return true;
else
return false;
}
?>
<?php
//test the function
$str1 = “mypasswordistoolong”;
if (CheckNoChars($str1))
//if its OK display this message
echo “this has the correct number of characters”;
//if its not OK display this one instead
else
echo “incorrect number of characters”;
?>

Share

Check For Alphanumeric characters

This example checks for alphanumeric charcters which in this case are lower case and upper case letters and the numbers 0 to 9 using regular expressions

<?php
// sample strings
$string1 = “abc123”;
$string2 = “abc123-+/~”;
//check string 1
if (ereg(‘[^A-Za-z0-9]’, $string1))
{
  echo “non alphanumeric”;
}
else
{
  echo “alphanumeric”;   
}
//check string2
if (ereg(‘[^A-Za-z0-9]’, $string2))
{
  echo “non alphanumeric”;
}
else
{
  echo “alphanumeric”;   
}

?>

Share

Check for numbers using Regular Expressions

Check for numbers only using regular expressions

<?php
// sample strings
$string1 = “123”;
$string2 = “abc123”;
//check string 1
if (ereg(‘[^0-9]’, $string1))
{
  echo “characters and numbers”;
}
else
{
  echo “numbers only”;   
}
//check string2
if (ereg(‘[^0-9]’, $string2))
{
  echo “characters and numbers”;
}
else
{
  echo “numbers only”;    
}

?>

Share

Email verify function

This is an email verification function using regular expressions

function checkEmail($address)
{
if(ereg( “^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)$”,$address) )
return true;
else
return false;
}

usage

checkEmail(testemail@testemail.com);

Share