Php 检查字符串是否为数字,但不包括欧元符号
我想能够添加产品的价格,但也只是一个文本。所以我建立了一个检查,看看字符串是否是数字。我的问题是,我显示的价格如下:Php 检查字符串是否为数字,但不包括欧元符号,php,Php,我想能够添加产品的价格,但也只是一个文本。所以我建立了一个检查,看看字符串是否是数字。我的问题是,我显示的价格如下: if($product['xreference'] != ''){ $price = '€ '.strip_tags($product['xreference']); }else{ $price = ''; } 那么,我如何检查$price是否为数字,但不包括支票中的欧元符号呢?假设您想在所述代码行之后进行数字检查,一种方法是: $priceTest =
if($product['xreference'] != ''){
$price = '€ '.strip_tags($product['xreference']);
}else{
$price = '';
}
那么,我如何检查$price是否为数字,但不包括支票中的欧元符号呢?假设您想在所述代码行之后进行数字检查,一种方法是:
$priceTest = str_replace('€', '', $price);
$result = is_numeric($priceTest);
if ($result) {
echo " it is numeric";
}
在将欧元添加到$price变量之前,可以检查数据是否为数字
if($product['xreference'] != ''){
if(is_numeric($price)){ // If data is numeric then add '€' to $price.
$price = '€ '.strip_tags($product['xreference']);
}
else
{
// data of $price is not numeric value
}
}
else
{
$price = '';
}
你可以使用str_替换我发布的一些代码可能会有所帮助
<?php
$price = 'dsf';
$productPrice['xreference'] = '€'.$price;
$onlyPrice = str_replace ("€","",$productPrice['xreference']);
if(ctype_digit($onlyPrice)){
echo "Yes";die;
}else{
echo 'not';die;
}
?>
如果$price=100;那么答案是肯定的MySQL与此有什么关系?不要做垃圾标签。