php - Why does this command output an empty array of the expected size instead of one with the elements filled in? -
this question has reply here:
how set string in array, split new line? 14 answersi want have user type in several lines textarea , have php assign them array, code have seems assign blank values array
html:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtm$ <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <h1>juniper ios translator</h1> <form method="post" action="query.php"> <textarea name="txtarea" style="width: 80%; height: 25em;"> </textarea> <input type="submit" /> </form>
php:
<?php $text = $_post["txtarea"]; echo nl2br($text); echo "<br />" , "<br />"; $data = preg_split("/((?<=\n).*?(?=\n))/", $text , -1, preg_split_no_empty); print_r(array_values($data)); ?> </body> </html>
with input:
line stuff line stuff more line stuff more more line stuff more more more line stuff more more more more
i output:
line stuff line stuff more line stuff more more line stuff more more more line stuff more more more more array ( [0] => [1] => [2] => [3] => [4] => [5] => )
am passing array wrong? regex wrong?
use
$data = preg_split("/\r/", $text , -1, preg_split_no_empty);
where \r symbolize end of line.
preg_split
takes delimiter first param. tried utilize text(not end of line)as delimiter , got end of lines array.
php arrays regex
No comments:
Post a Comment