[英]Need to Replace Colons and Forward Slashes in String with Nothing
這是我的代碼:
add_filter('frm_validate_field_entry', 'my_function_name', 8, 3);
function my_function_name($errors, $posted_field, $posted_value)
{
if($posted_field->id == 5)
{
$chbaa = strtolower($_POST['item_meta'][1]);
$chbab = strtolower($_POST['item_meta'][2]);
$chbac = strtolower($_POST['item_meta'][3]);
$chbad = strtolower($_POST['item_meta'][4]);
$_POST['item_meta'][5] = preg_replace('/\s+/', '', $chbaa) . preg_replace('/\s+/', '', $chbab) . preg_replace('/\s+/', '', $chbac) . preg_replace('/\s+/', '', $chbad);
}
return $errors;
}
當前,這會刪除不同字段中的所有空格,並將所有內容都轉換為小寫,將四個字段組合為一個字符串。 但是,字段1( $chbaa
)和字段4( $chbad
)分別包含正斜杠和冒號。 字段1是日期,因此其格式為00/00/0000,字段4是時間,因此其格式為00:00:00。 我需要從字符串中刪除兩個正斜杠和兩個冒號,什么都不要替換。
我想到了。 我將字段1和4的/ \\ s + /替換為/ [^ 0-9] /,就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.