[英]How to insert 2 digit number in database after preg_match?
preg_match_all('#(\d[wW]+|\d[dD]+|\d[hH]+|\s+)#i', $category, $matches); $hours=0; $days=0;
$hoursss=0;
foreach($matches[0] AS $match) {
switch(true) {
case preg_match('/\d[hH]+|\s+/', $match) :
$hours +=(int)$match;
break;
case preg_match('/\d[dD]+|\s+/', $match) :
$days +=(int)$match*24;
break;
case preg_match('/\d[wW]+|s+/', $match) :
$hoursss+= (int)$match*24*7;
break;
}
$case=$hours+$hoursss+$days;
}
當我輸入2d2w2h時,它將轉換為總小時數並插入數據庫。
但是,當我給出input20w20d20h時,它在數據庫中給出0。
請幫幫我
您的第一個正則表達式是錯誤的(匹配句號前的多個數字),應該是:
#(\d+[wW]+|\d+[dD]+|\d+[hH]+|\s+)#i'
還請檢查其他正則表達式是否存在某些極端情況,因為處理所有正則表達式的方法並非完美無缺。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.