Harsh Sanghani Harsh Sanghani - 5 months ago 17
PHP Question

Combine two textarea value with line breaks using PHP

I have two different

textarea
and I want to store that both in one field of database with line breaks. Its working good if I store one
textarea
value in table field, But I need to store both
textarea
value in one field.

Example :-

textaera 1)

Hello
text from textarea1


textarea 2)

How are you?
its second textarea text


Output that I need with all line breaks and also between two
textarea
value :-

Hello
text from textarea1
How are you?
its second textarea text

Answer

Suppose you both values are coming into variables $textarea1 and $textarea2 correspondingly. You can do it like below:-

$combine_data = $textarea1."\n".$textarea2;

OR

$combine_data = $textarea1 . PHP_EOL . $textarea2; and use nl2br($combined) to show it again in text-area //@iainn suggestion

OR

$combine_data = $textarea1 ."<br/>". $textarea2;

Reference Taken :-

add line break between 2 variables