Forum Moderators: coopster
For example, if I have the following:
Name of person
555-555-5555
123 Address Road,
City, ON K1J 9E8
Is it possible to seperate this so that when I submit my form, it will insert the name, number, address, city, province, postal code into different MySQL records?
Can I make it so that:
$name = THE_FIRST_LINE
$number = THE_SECOND_LINE
$address = THE_THIRD_LINE (without the final ",")
$city = PART_BEFORE_FIRST_COMMA
$province = PART_BETWEEN_FIRST_AND_SECOND_COMMA
$postalcode = LAST_7_CHARACTERS_OF_LINE_4
?
<?php
$pieces = explode("
", $_POST['formfield']);
// here you transform the data in the field form into an array, with the items split for every new line
$name = $pieces[0]; // first line
$number = $pieces[1]; // second line
?>
etc. With strlen() and substr() you could take out the comma and select postal code etc.
Check also:
[php.net...]
[php.net...]
[php.net...]
(you could use strlen to find the length of the address, and then chop it off 1 character before it ends -- to get rid of the comma)