I have an HTML form. When filled out I have four strings. I want to check the strings for:
only digits and commas are permitted in the string - I’m guessing I’d use preg_match here
if the last item is a comma then strip that comma off. I’m currently using a check like this, is it the most efficient way?
$FormFieldOne = "7,8,";
if (strripos($FormFieldOne,",") == strlen($FormFieldOne)-1) {
// last character is a hanging comma, strip it off
$FormFieldOne = substr($FormFieldOne, 0, -1);
}
If step 2 is efficient and I wanted to do this with all four form fields, I’m assuming I could assign them to an array and use each/foreach to step through but how do I refer to the variable name $FormFieldOne correctly?
I know I can reference $myarray[0] to get the contents of $FormFieldOne but how do I refer to the variable $FormFieldOne so I can use substr to strip off that last character?