简体   繁体   中英

php print each line from textarea

i have this code

<textarea rows="4" cols="50"  type="text" name="ytburl" /></textarea>       
<input type="submit" value="START" name="submit" />

$ytburl = $_POST["ytburl"];
echo 'link '.$ytburl.' is here'

so if in textarea i put 2 links:

example.com/11111

example.com/22222

then i get this output:

link example.com/11111 example.com/22222 is here

i want to get this output:

link example.com/11111 is here

link example.com/22222 is here

If you want to just print text like it was sent you can use nl2br() function to replace all new line characters to HTML tags.

But it's not best idea to just print data unfiltered so combine it with strip_tags() function.

echo nl2br(strip_tags($variable));

Try this

<?php
$arrLines = explode(' ', $variable);
foreach($arrLines AS $line){
    echo $line . '<br/>';
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM