samedi 3 janvier 2015

Save line break in textarea with php?


How do I save line breaks in a textarea with php? Currently I have this temporary solution by using exec to execute a shell string to get the job done but if possible I want it to be all in php. Here's my temporary script, please tell me how should I edit it



<?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>';
?>


If I use nl2br the output file will be like this



satu<br />
dua<br />
tiga<br />
empat<br />
lima


I don't want those <br /> in there. Here's the script with nl2br in it:



<?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>';
?>


NOTE I want the output of my file test.txt to be like this WITHOUT the <br /> part



satu
dua
tiga
empat
lima




Aucun commentaire:

Enregistrer un commentaire