0

Whenever I receive input such as from a HTML Textarea box:

 [email protected]:25wfsfrs
 [email protected]:324dasd
 [email protected]:3dsadasd

I want to use the PHP function explode() on the colon and print out a list such as:

Usernames:
1st Email
2nd Email
3rd Email

Passwords:
1st Pass
2nd pass
3rd Pass

Code so far:

<html>
<head>
<title>
Usernames AND Passwords!
</title>
</head>
<body>


<?php
/*Print contents of textarea for testing purposes.*/

$data = explode("\n", $_POST['uandp']);
foreach($data as $value){
    echo $value;
}

/*Split username and password*/
$string = $_POST['uandp']; 
list($string1,$string2) = explode(":",$string);  
/*$string1 = username, $string2 = password*/ 
$new_string = $string1;
$new_string2 = $string2;
/*$new_string = Username*/
/*$new_string = Password*/

echo $new_string;
echo $new_string2;
?>
</body>
</html>

Not sure where to go from here. I know I have to store the textarea form data into an array and parse it from there.

1 Answer 1

3
$uAndPs = array();

foreach (explode("\n", $_POST['uandp']) as $value){
    list($username, $password) = explode(':', $value);
    $uAndPs[$username] = $password;
}

echo "Usernames:\n"
echo join("\n", array_keys($uAndPs));

echo "Passwords:\n"
echo join("\n", $uAndPs);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.