سؤال

I have a php form which add a textarea field value, to a zip file. It work well the, but it doesn't keep break lines. This is my code:

<script src="//jquery.min.js"></script
<textarea id="txtLicense" placeholder="Licencia">
You are free to use this file
Creative Commons License
</textarea>
<input type="button" value="Send" id="send">
<script>
$("#send").on("click", function(){
    var txtLicense = $("#txtLicense").val();
    $.ajax({
        type: 'POST',
        url : 'ajax/zipIt.php',
        data: {cmd:"zitTxt", txtLicense:txtLicense},
        success: function(data){
            console.log(data);
        }
    });
});

php

<?php
if($_POST['cmd'] == "zitTxt"){
$txtLicense = $_POST['txtLicense'];
$za = new ZipArchive();
$za->open('zips/lic.zip');
$za->addFromString('file.txt', $txtLicense);
$za->close();
echo "ok";
}
?>

By te way I already tried whit "nl2br" but it returns the same string in one line with <br /> inside:

You are free to use this file <br />Creative Commons License

Any help with this problem would be much appreciated

هل كانت مفيدة؟

المحلول

Try this

$txtLicense = $_POST['txtLicense'];
$txtLicense = str_replace("\n","\r\n", $txtLicense);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top