Сохранить текстовый файл в Zip-файле с сохранением строки разрыва PHP

У меня есть php-форма, которая добавляет значение поля textarea в zip-файл. Он работает хорошо, но не держит линии разрыва. Это мой код:

<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";
}
?>

Кстати, я уже пробовал использовать "nl2br", но он возвращает ту же строку в одной строке с <br /> внутри:

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

Любая помощь с этой проблемой будет высоко оценена


person Kakitori    schedule 18.03.2014    source источник


Ответы (1)


Попробуй это

$txtLicense = $_POST['txtLicense'];
$txtLicense = str_replace("\n","\r\n", $txtLicense);
person Nauphal    schedule 18.03.2014