Page 1 of 1
No integer (0 to 9) is allowed in a string
Posted: Sun Nov 09, 2008 8:26 am
by chxxangie
how to do identify a string inside has no integer (0 - 9)?
when i try to write source code for this, it make me blur...
please help... thanks...
Re: No integer (0 to 9) is allowed in a string
Posted: Sun Nov 09, 2008 8:49 am
by chxxangie
finally has done. but the length code is a bit long...
Code: Select all
<?php
function to_echo($f_input1,$f_input2,$debug){
if($debug == 1){
echo $f_input1. " => ".$f_input2."<br>";
}
}
$name = "lu chen";
to_echo("name",$name,1);
$name1 = str_replace(" ","",$name);
to_echo("name",$name1,1);
$len_name1 = strlen($name1);
to_echo("length name",$len_name1,1);
for($a=1;$a<$len_name1+1;$a++){
$char_name = substr($name1,$a-1,1);
echo "str: ".$char_name."<br>";
if(is_numeric($char_name)){
echo "contain integer!"."<br>";
}
}
?>
Re: No integer (0 to 9) is allowed in a string
Posted: Sun Nov 09, 2008 10:21 am
by Syntac
Code: Select all
if( preg_match( "#[0-9]#", $string ) )
echo "String contains numbers.";
else
{
// do stuff
}
Re: No integer (0 to 9) is allowed in a string
Posted: Sun Nov 09, 2008 11:57 am
by Mark Baker
Code: Select all
if (strtok($testString,'0123456789') != $testString) {
echo 'String contains numeric values';
} else {
echo 'String contains no numeric values';
}