正如標題所說,我有一個變量,用於存儲來自客戶的數據輸入,如果數據包含英鎊符號,則表示他們輸入的是英鎊簽收產品的價格,如果不包含英鎊符號,則需要確保將其添加。使用IF語句來檢查變量是否包含£(磅)登錄PHP
我知道PHP使用多字節字符。這是我如何檢查,但它不工作:
if(($price[0] != "Â") && ($price[1] !="£")){
$len = strlen($price);
$char= '£';
for($t = 0; $t<$len;$t++){
$char .= $price[$t];
}
$price = $char;
}
我怎麼能得到這個工作?
您可以使用strpos功能。看看這裏php.net/manual/en/function.strpos.php –
你可以使用'strpos' http://php.net/manual/fr/function.strpos.php – teeyo
if(strpos(「£」 ,$ price)!== false){/ * It's there * /}' – Qirel