PHP Snippets
more_nums
Information
(PHP Version >= 3)Functions used in this snippet: strlen, str_replace.
Description
bool more_nums( mixed str )
Returns true if the given string str contains more numbers than characters. Returns false if not.
Snippet
<?php
function more_nums($str){
$len = strlen($str);
$str = str_replace(array(0,1,2,3,4,5,6,7,8,9), '', $str);
if( ( strlen($str) / $len ) < 0.5)
{
return true;
}
return false;
}
?>
Example
more_nums Can be used in the following way:
<?php
$str = 'abcd123';
if(more_nums($str))
{
echo 'More Numbers';
}
else
{
echo 'Less Numbers';
}
$str = 'ab12345cd6';
if(more_nums($str))
{
echo 'More Numbers';
}
?>
Updated on Oct 19th at 9 pm.
0 Responses to more_nums