I have a basic textarea. When user enter some text I explode words by comma ",". Now I also want to seperate words by new line. How can I do it.
This is my code part that explodes words by comma.
if(isset($_POST["btn"])){
$words = $_POST["inp_text"];
$words_arr = explode(",",$words);
foreach($words_arr as $word){
echo $word."<br>";
}
}
How can I add new line functionality to this code part. I think, I should generate a string from $word
in loop than after loop I should explode this string by new line again.
Is there a better idea?
For better understading I add some examples.
input:
apple, melon, a, b, c
output:
apple melon a b c
input (with new line)
x,y,z,a
b
c
output:
x y z a b c