[英]php loop through each string line in textarea
我正在使用此脚本从数组中的文本区域获取每一行:
//trim off excess whitespace off the whole
$text = trim(get_field('backlinks'));
//explode all separate lines into an array
$textAr = explode("\n", $text);
//trim all lines contained in the array.
$textAr = array_filter($textAr, 'trim');
//loop through the lines
var_dump($textAr);
foreach ($textAr as $line) {
echo $line;
}
我从var_dump
输出是:
array(3) { [0]=> string(29) "
http://www.nasa.gov/
" [1]=> string(25) "http://www.cnn.com/
" [2]=> string(27) "http://www.twitter.com/
" }
我的html输出来自echo $line;
是:
http://www.nasa.gov/<br>
http://www.cnn.com/<br>
http://www.twitter.com/
我的脚本处理错误。 我需要echo $line;
的输出echo $line;
成为:
http://www.nasa.gov/http://www.cnn.com/http://www.twitter.com/
我的var_dump
的输出为:
array(3) { [0]=> string(29) "http://www.nasa.gov/" [1]=> string(25) "http://www.cnn.com/" [2]=> string(27) "http://www.twitter.com/" }
我不想在输出/回声中换行。 我究竟做错了什么?
提前致谢
//trim off excess whitespace off the whole
$text = trim(get_field('backlinks'));
//explode all separate lines into an array
$textAr = explode("\n", $text);
//trim all lines contained in the array.
$textAr = array_filter($textAr, 'trim');
//loop through the lines
var_dump($textAr);
foreach($textAr as $line) {
echo str_replace("\n","",str_replace("\r","",$line));
}
尝试使用impload。
echo implode(“,”,$ textAr);
对不起,我以为这是PHP代码,这是我的textarea的设置,每行之后都会有一个<br>广告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.