有没有办法在textarea(php)中保持换行符?

时间:2014-12-23 07:25:51

标签: php

我有这个脚本

<?php
include 'theme.php';
/*ceklogin();*/
css();
if($_POST['wget-send'])
    {
        $dir=$_POST['dir'];
        $link=$_POST['link'];
        exec('echo '.$link.' > /tmp/wget-download-link.txt',$out);
        exec('wget -P '.$dir.' -b -i /tmp/wget-download-link.txt -o /www/wget.log -c -t 100 -w 10',$out);
        echo $out[2];
        exit();
    }
echo "<br><br><form action=\"".$PHP_SELF."\" method=\"post\">";
echo "Download directory :<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/><br>";
echo '<br>Download link :<br>';
echo ("<textarea name=\"link\" rows=\"11\" cols=\"60\"></textarea><br><br>");
echo '<input type="submit" name="wget-send" value="Send" />';
echo "</form></div>";

foot();
echo '
</div>
</body>
</div>
</html>';
?></div>
</html>';
?>

每当我输入两行或更多行的文本时,它们都不会保存在/tmp/wget-download-link.txt中。该文件始终为空,但是当我只输入只包含一行的文本时,它会保存在那里。我希望我的wget-download-link.txt文件是这样的:

http:xxx1
http:xxx2
http:xxx3

有没有办法做到这一点?

2 个答案:

答案 0 :(得分:1)

您需要使用“\ n”在字符串中添加换行符。

答案 1 :(得分:0)

带有echo命令的新行字符是&#34; \ n&#34;。以下面的例子为例:

echo "This is line 1\nThis is line 2" > /tmp/hallo_world.txt

所以你应该工作

exec('echo "'.$link.'" > /tmp/wget-download-link.txt',$out);

在此之前,你应该 $ link 替换\ n中的\ r \ n,并在$ link内容中屏蔽doublequoats ....