Say I have a form that has 3 text fields for the user to enter the 3 parts of a phone number. 3 numbers each will be entered into the first and second fields, and 4 numbers will be entered into the third field.
Then, after the user submits the form, the three groups of numbers will be concatenated something like this...
$phonenumber = "(" . $areacode . ") " . $prefix . "-" . $lastfour;
$phonenumber will then be stored in the database.
Now, say I'd like to edit a particular record, and have the three parts of the phone number appear in the same type of text fields, where they can be edited. I know how to get the variable, and how to display variables in the text boxes. When I get the variable from the database, it'll be something like this..."(555) 555-5555". So anyway, my question is...is there a way I could pull the first three numbers out of that variable and put that value in a variable, and do the same thing with the other two groups of numbers, so I could then put each value in the appropriate field? (I hope that made sense.)if you stored the phone number like 123-456-7890 then all you would have to do is
<?php
$number = "123-456-7890";
$number = explode("-", $number);
?>
(<input type="text" value="<?php echo $number[0]; ?>" />)
<input type="text" value="<?php echo $number[1]; ?>" /> -
<input type="text" value="<?php echo $number[2]; ?>" />
i would recommend that for ease
but if you have to store it the other way, then learn regular expressions, and use split() or preg_split(). i dont really know them so i couldnt help youThanks for the help, n8. It doesn't really matter how I store it, so that'll work perfectly.
Then, after the user submits the form, the three groups of numbers will be concatenated something like this...
$phonenumber = "(" . $areacode . ") " . $prefix . "-" . $lastfour;
$phonenumber will then be stored in the database.
Now, say I'd like to edit a particular record, and have the three parts of the phone number appear in the same type of text fields, where they can be edited. I know how to get the variable, and how to display variables in the text boxes. When I get the variable from the database, it'll be something like this..."(555) 555-5555". So anyway, my question is...is there a way I could pull the first three numbers out of that variable and put that value in a variable, and do the same thing with the other two groups of numbers, so I could then put each value in the appropriate field? (I hope that made sense.)if you stored the phone number like 123-456-7890 then all you would have to do is
<?php
$number = "123-456-7890";
$number = explode("-", $number);
?>
(<input type="text" value="<?php echo $number[0]; ?>" />)
<input type="text" value="<?php echo $number[1]; ?>" /> -
<input type="text" value="<?php echo $number[2]; ?>" />
i would recommend that for ease
but if you have to store it the other way, then learn regular expressions, and use split() or preg_split(). i dont really know them so i couldnt help youThanks for the help, n8. It doesn't really matter how I store it, so that'll work perfectly.