Saturday, 7 September 2013

Need to Replace Colons and Forward Slashes in String with Nothing

Need to Replace Colons and Forward Slashes in String with Nothing

Here's my code:
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;
}
This currently removes all spaces from the different fields and drops
everything to lowercase, combining the four fields into one string. Fields
1 ($chbaa) and 4 ($chbad), however, include forward slashes and colons
respectively. Field 1 is a date, so it's formatted 00/00/0000 and field 4
is the time, so it's formatted 00:00:00. I need to remove the two forward
slashes and the two colons from the string, replaced with nothing.

No comments:

Post a Comment