Input ==== email1 name1 email2 name2 email3 name3 output ==== email1 | name1 email2 | name2 email3 | name3 anyone help me please?
when you get those variables from a form <?php $email1 = $_POST['email1']; $name1 = $_POST['name1']; $email2 = $_POST['email2']; $name2 = $_POST['name3']; $email3 = $_POST['email3']; $name3 = $_POST['name3']; $final_line_1 = $email1 . " | " . $name1; $final_line_2 = $email2 . " | " . $name2; $final_line_3 = $email3 . " | " . $name3; ?> PHP: Hope this example above will help you to understand how to do that
@UtsavT Defining every variable is unnecessary. If your source is a regular form, then you can on submit get the info by using the $_POST variable without defining each of them. For an example echo $_POST['email1'].' seperator '.$_POST['name1']; echo $_POST['email2'].' seperator '.$_POST['name2']; PHP:
Maybe this: <?php $input = 'email1 name1 email2 name2 email3 name3'; $output = ''; $temp = explode("\n", $input); $count = count($temp); for ($x = 0; $x < $count; $x=$x+2) { $output .= $temp[$x] . ' | ' . $temp[$x+1] . "\n"; } unset($temp); echo $output; PHP:
The other way is: <?php $users = array(); $users[] = array("email" => $_GET['email1'], "name" => $_GET['name1']); $users[] = array("email" => $_GET['email2'], "name" => $_GET['name2']); $users[] = array("email" => $_GET['email3'], "name" => $_GET['name3']); foreach($users as $user) { $newline = $user['name'] . " | " . $user['email']; echo $newline; } ?> PHP: If it is not working check $_GET.. maybe needs $_POST.
Lol, guys it should be just: $e = explode('\n', $input); $output = implode(' | ', $e); Code (markup):
yes but he need to manage the emails and names with some way. Where he found the $input array? somehow must create the array.. what better from key-value arrays..