Php Randomize Array (Shuffle)

September 27th, 2007 by Sajith M.R

images.jpg

If you want to randomize a php array , you can use shuffle function.

But we can’t randomize the whole array with its value, it might be integer, string or collection of objects etc. So we randomize or shuffle the keys of the array.

Eg:

$Keys = array_keys($MyArray);
shuffle($Keys);

$NewArray = array(); //declare a new array
foreach( $Keys as $key)

{

$NewArray[] = $MyArray[$key];

}

Here the NewArray will be the shuffle of MyArray

Thanks

Sajith.M.R

Some More About Propel

September 27th, 2007 by Sajith M.R

Propel Random Criteria >>

$c= new Criteria();
$c->addAscendingOrderByColumn('rand()');
$TagRs = TagPeer::doSelect($c );

?>

This code will give you the result in random manner. Here in this example, i show the random tags from Tag Table.

Propel Memory Optimization using Result Set >>

if you use

$TagRs= TagPeer::doSelect(new Criteria());

The whole result of the query will be saved in $TagRs as array (Means usage of memory to save whole the table rows).
But if you want two columns of this table, the rest are wastage of memory. In that case you can use result set after selecting the
desired columns.

Read More »

Php Regular Expressions and Validations

September 1st, 2007 by Sajith M.R

regular.jpg

Php regular expression to validate an email address


$email = 'sajithmr2005@yahoo.com';
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",
$email))
{
echo 'valid email' ;
}

?>

//Regular Expression for Validate a number

$mobile = '9846831106';

if ( ereg('^[[:digit:]]+$', $mobile) )

{

echo 'valid number';

}

?>

Regular Expression for Removing non-alphabetic characters from a string or a Filename.

$newFilename = preg_replace(”/[^a-zA-Z0-9s.]/”, “”, $newFilename);

Yslow

September 1st, 2007 by Sajith M.R

firefox.png5369.png

Yslow >>> Why my website is slow ??

Yslow is an addon for mozilla integratted with firebug (Another addon from
mozilla).

Yslow checks the web page and tells us what are the slow factors in the current
webpage and it put grade for a particular web page

High speed webpages get grade A. (Google is an example for A grade website)
and the grade varies to B, C , D etc depends on the speed of the webpage

Yslow catagarises the slow factors into 13 parts.

http://developer.yahoo.com/yslow/

Use this link for more details.

https://addons.mozilla.org/en-US/firefox/addon/5369

Install yslow from above url.