如何检查一个单词中是否存在数字


How to check if any number exists in a word

例如,如果我的单词是$item = '3.5Floppy'$item = '3Floppy'$item = '4520Floppy'

我想检查我的单词中是否存在数字?

尝试preg_match很简单,是否有任何数字?

if(preg_match('/('d)/', $item))
{
     echo "Number Found!";
}

'd的平均值为Any digit

Regex文档:http://php.net/manual/en/function.preg-match.php

Use regex (preg_match):

$hasNumberInside = preg_match("/[0-9]/", $string);
if ($hasNumberInside === true) {
    echo 'String with number';
} else {
    echo 'No numbers inside';
}
echo (ereg ("[0-9]{1,}", $item) ? "true" : "false");