Finding Items in an Array or not with PHP

The problem: we have an array of items in PHP and we want to find out if a specific item is in the array. In code we can define the array as:
Read the rest of this entry »

Make a string’s first character uppercase

ucfirst — Make a string’s first character uppercase

example:

$coo= ‘clay desiccant!’;
$coo= ucfirst($desiccant); // Clay desiccant!

$bar = ‘CLAY DESICCANT!’;
$bar = ucfirst($bar); // CLAY DESICCANT!
$bar = ucfirst(strtolower($bar)); // Clay desiccant!

Read the rest of this entry »

How to show all files in a document?

$dirname=”E:/zhanzhongjie/chengbiao-com/chengbiao-com”;
$dir_handle=opendir($dirname);
while($file=readdir($dir_handle)) Read the rest of this entry »

Php generate random numbers

/*random function
$length: length of needed number
*/
function random($length) {
$hash = ”;
$chars = ‘0123456789′;
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
} Read the rest of this entry »

rename()

— Renames a file or directory

Description
bool rename ( string $oldname , string $newname [, resource $context ] )
Attempts to rename oldname to newname . Read the rest of this entry »

fwrite() example

Description
int fwrite ( resource $handle , string $string [, int $length ] )
fwrite() writes the contents of string to the file stream pointed to by handle . Read the rest of this entry »

chr — Return a specific character

Description
string chr ( int $ascii )
Returns a one-character string containing the character specified by ascii . Read the rest of this entry »