Reputation: 1097
I want to create like a notepad in js and php but I want it to add some spaces for each new line I thought I can make it with a textarea, but I dont know how to This is my idea:
<textarea name="text"></textarea>
and in PHP
$text = trim($_POST['text']);
$textAr = explode("\n", $text);
$textAr = array_filter($text, 'trim'); // remove any extra \r characters left behind
foreach ($textAr as $line) {
$height = $height + $line_height;
}
But not really sure it works. Any idea?
Upvotes: 2
Views: 153
Reputation: 47620
$textAr = array_filter($text, 'trim'); seems to be wrong.
$text
while you already have $textAr
and want use it array_map
, not array_filter
Upvotes: 1
Reputation: 3202
Maybe my brain is already sleeping, but did you maybe mean
$textAr = array_filter($textAr, 'trim');
Upvotes: 1
Reputation: 324650
You are basically discarding the explode
step. Try this instead:
$textAr = array_filter(preg_split("/[\r\n]+/",$_POST['text']));
This basically allows any format of newline, and removes empty lines. You can then pass $textAr
through foreach
.
Upvotes: 0