Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textarea to array preserving line breaks 2

Status
Not open for further replies.

CliveC

Programmer
Nov 21, 2001
1,222
US
Without having to modify TEST1.HTM, can anyone think of a way in TEST1.PHP to capture the four lines in a string array that would be accessible by line number and which would preserve line breaks and blank lines?

Code:
TEST1.HTM
<html><body>
<form name="mail" method="post" enctype="multipart/form-data"
 action="test1.php">
Message:<br /> 
<textarea name="t" rows="6" cols="36">
line-1
line-2

line-4
</textarea><br />
<input value="Send" type="submit" />
</form></body></html>

Code:
<?php
$line=array();
$text=$_POST['t'];
?>

Clive
 
Something like:
Code:
$lines = explode( $text, "\n" );
You may have to play with the newline character.
 
you can try:

$text_array = explode("\n", $text);

this will preseve empty lines (I think).
If you want also the breaklines, you have to add "\n" at the end of each element of array.




___
____
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top