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...
No integer (0 to 9) is allowed in a string
Moderator: General Moderators
Re: No integer (0 to 9) is allowed in a string
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
Code: Select all
if( preg_match( "#[0-9]#", $string ) )
echo "String contains numbers.";
else
{
// do stuff
}-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: No integer (0 to 9) is allowed in a string
Code: Select all
if (strtok($testString,'0123456789') != $testString) {
echo 'String contains numeric values';
} else {
echo 'String contains no numeric values';
}