Forum Moderators: coopster
I'm just trying to get the information typed into MyTextarea to break onto a new line in TextareaHandler.php. When submitted the text is all in one single line across the page giving me a horizontal scrollbar...I don't thing I'm mistyping anything here- Is the nl2br function correct?
form.html
_____________
<html>
<head>
<title></title>
</head>
<body>
<form action="TextareaHandler.php" method="post">
<textarea cols="40" rows="5" name="MyTextarea"></textarea>
<input type="submit" value="Send Form" />
</form>
</body>
</html>
TextareaHandler.php
_____________________
<?php
$MyTextarea = nl2br($MyTextarea);
echo($MyTextarea);
?>
-Thanks
[edited by: madcat at 7:18 pm (utc) on Aug. 5, 2002]
$_REQUEST['MyTextarea'] = ereg_replace("(\r\nŠ\nŠ\r)", "<br />",$_REQUEST['MyTextarea']);
And I get an error on line 2. Oh yeah, also:
$MyTextarea = ereg_replace("(\r\nŠ\nŠ\r)", "<br />",$MyTextarea);
Same error-
Everything is spelled out correctly, so ?
So, if you enter one long line in the textarea (with no carriage returns) that's what you'll get out of it, and the nl2br() function won't have any newlines to change to breaks.
That's where the wordwrap() function comes in: notice it's set to 39 characters. That's approximately the width of your textarea (cols="40") so it will emulate the text as it appears in the textarea box by wrapping at the 39th character.
No need for fancy eregs. :)
<?php
$MyTextarea = wordwrap($MyTextarea, 39);
$MyTextarea = nl2br($MyTextarea);
echo($MyTextarea);
?>
The problem is that anything I try won't wrap. I could be way off but I feel like I might have to change something in php.ini?
Between all of the examples presented above, there is no way that one of those shouldn't be working correctly.
Windows 2000 / Apache if that helps.
Yes, I think that's safe.
Must be frustrating.
For the sake of coordination in this problem-solving venture copy this code:
<html>
<head>
<title></title>
</head>
<body>
<form action="TextareaHandler.php" method="post">
<textarea cols="40" rows="5" name="MyTextarea"></textarea>
<input type="submit" value="Send Form">
</form>
</body>
</html>
<?php
$MyTextarea = wordwrap($MyTextarea, 39);
$MyTextarea = nl2br($MyTextarea);
echo($MyTextarea);
?>
...save it as TextareaHandler.php, run it, then stuff this one long line into the form:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat. Ut wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis te feugifacilisi.
...see if it wraps.
I just want to duplicate what I'm doing here.