Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用php在textarea中保存换行符?_Javascript_Php - Fatal编程技术网

Javascript 用php在textarea中保存换行符?

Javascript 用php在textarea中保存换行符?,javascript,php,Javascript,Php,如何使用php在文本区域中保存换行符?目前,我使用exec执行一个shell字符串来完成任务,这是一个临时解决方案,但如果可能的话,我希望它都是php。这是我的临时脚本,请告诉我应该如何编辑它 <?php include 'theme.php'; /* ceklogin(); */ css(); if ($_POST['wget-send']) { $formdir = $_POST['dir']; $formlink = $_POST['link']; $fil

如何使用php在文本区域中保存换行符?目前,我使用
exec
执行一个shell字符串来完成任务,这是一个临时解决方案,但如果可能的话,我希望它都是php。这是我的临时脚本,请告诉我应该如何编辑它

<?php

include 'theme.php';
/* ceklogin(); */
css();
if ($_POST['wget-send']) {
    $formdir = $_POST['dir'];
    $formlink = $_POST['link'];
    $filelink = fopen('/root/wget/wget-download-link.txt', a);
    $filedir = fopen('/root/wget/wget-dir.txt', w);

    fwrite($filedir, $formdir);
    exec('echo "' . $formlink . '" >> /root/wget/wget-download-link.txt', $out);
    echo $out[2];
    exit();
}

if ($_POST['restart-download']) {

    exec('mv /root/wget/wget-download-link.txt.done /root/wget/wget-download-link.txt');
    exit();
}

echo "<form action=\"" . $PHP_SELF . "\" method=\"post\" id=\"WgetForm\">";
echo "Download directory:<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/>    <br>";
echo '<br>Download link:';
echo ("<textarea name=\"link\" rows=\"13\" cols=\"62\"></textarea><br>");
echo '<input type="submit" onclick="LinkAdded()" name="wget-send" value="Download" id="WgetID"/><br>';
echo '<input type="submit" onclick="DownloadRestarted()" name="restart-download" value="Restart latest download" id="RestartWget"/>';
echo "</form></div>";
echo <<<HTML
<script type="text/javascript">

function LinkAdded(){

        alert("Link has been sucessfully sent to wget, it'll be downloaded soon, check the wget log for the download progress");
}

function DownloadRestarted(){

        alert("Download restarted, check the wget log for the download progress");
}

</script>
 HTML;
 foot();
 echo '
 </div>
 </body>
 </div>
 </html>';
 ?>
我不想要那些

在那里。下面是包含
nl2br
的脚本:

<?php
include 'theme.php';
/*ceklogin();*/
css();
if($_POST['wget-send'])
    {
        $formdir=$_POST['dir'];
        $formlink=$_POST['link'];
    $filelink = fopen('/root/wget/test.txt',a);
    $filedir = fopen('/root/wget/wget-dir.txt',w);

    $savelink = nl2br($formlink);
    fwrite($filedir, $formdir);
    fwrite($filelink, $savelink);

    }

if($_POST['restart-download'])
    {
    exec('mv /root/wget/wget-download-link.txt.done /root/wget/wget-download-link.txt');
    exit();
    }

echo "<form action=\"".$PHP_SELF."\" method=\"post\" id=\"WgetForm\">";
echo "Download directory:<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/><br>";
echo '<br>Download link:';
echo ("<textarea name=\"link\" rows=\"13\" cols=\"62\"></textarea><br>");
echo '<input type="submit" onclick="LinkAdded()" name="wget-send" value="Download" id="WgetID"/><br>';
echo '<input type="submit" onclick="DownloadRestarted()" name="restart-download" value="Restart latest download" id="RestartWget"/>';
echo "</form></div>";
echo <<<HTML
<script type="text/javascript">

function LinkAdded()
    {
            alert("Link has been sucessfully sent to wget, it'll be downloaded soon, check the wget log for the download progress");
    }
function DownloadRestarted()
    {
            alert("Download restarted, check the wget log for the download progress");
    }

</script>
HTML;
foot();
echo '
</div>
</body>
</div>
</html>';
?>
将文本区域保存到数据库或文本文件时使用。然后,您只需在文本区域中回显:

<?php

// Input (can be saved in database or text file)

$toSave = nl2br($_POST["link"]);

// Output (from databse or text file)

echo "<textarea name=\"link\" rows=\"13\" cols=\"62\">$output</textarea><br>";

?>


我根本不明白这个问题。这两个文件是从哪里来的?他们是干什么的?你的文档注释在哪里?你想做什么?换行符已经存在,并保留在文本区域中。我理解,但如果不添加

或其他内容,您就不能这样做。当您想从文本文件中输出文本区域时,您可以尝试使用
nl2br
,或者这就是问题所在吗?尝试使用nl2br,然后使用
str_replace(“
,”,“$toSave)
@SkyLavi我并没有完全理解OP的问题。他希望每个单词都在一个新行上,sans
和sans\n?为什么要调用一个函数来生成

子字符串,然后再调用另一个来删除它们?@Lightness在轨道上运行他不希望代码中包含

satu
dua
tiga
empat
lima
<?php

// Input (can be saved in database or text file)

$toSave = nl2br($_POST["link"]);

// Output (from databse or text file)

echo "<textarea name=\"link\" rows=\"13\" cols=\"62\">$output</textarea><br>";

?>