Random string

December 5, 2008 by admin  
Filed under PHP

generates a random string from an array of characters

<?php
// function to generate random strings
function RandomString($length=32)
{
$randstr=”;
srand((double)microtime()*1000000);
//our array add all letters and numbers if you wish
$chars = array ( ‘a’,'b’,'c’,'d’,'e’,'f’);
for ($rand = 0; $rand <= $length; $rand++)
{
$random = rand(0, count($chars) -1);
$randstr .= $chars[$random];
}
return $randstr;
}
?>

and call it like this

<?php
echo RandomString(8);
?>

PHP and cURL example

December 4, 2008 by admin  
Filed under PHP

<?php
//the site or URL to get
$ch = curl_init(""http://www.google.com/"");
//set the options for the transfer
curl_setopt($ch, CURLOPT_HEADER, 0);
//execute the session
curl_exec($ch);
//free up system resources !!IMPORTANT
curl_close($ch);
?>

read contents of a directory

December 2, 2008 by admin  
Filed under PHP

reads in the contents of a directory and display as links

<?
function directory($result)
{

$handle=opendir(""."");
while ($file = readdir($handle))
{
if ($file == ""."" || $file == "".."")
{
}
else
{
print ""<a href=$file>$file</a><br>"";
}

}
closedir($handle); return $result;
}
echo directory($result);
?>

Read an ini file

December 1, 2008 by admin  
Filed under PHP

The contents of the ini file are listed below

[settings1]
text1 = "hello"
text2 = "world"

[settings2]
number1 = 4
number2 = 8

//print out all of the contents of the test.ini file

<?php
$ini_array = parse_ini_file("test.ini");
print_r($ini_array);
?>

Email verify function

November 22, 2008 by admin  
Filed under PHP

Email verify function with PHP

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;
}

Next Page »