Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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/250.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文件内容在空格后截断字符串_Javascript_Php_Jquery_Html_Truncate - Fatal编程技术网

Javascript php文件内容在空格后截断字符串

Javascript php文件内容在空格后截断字符串,javascript,php,jquery,html,truncate,Javascript,Php,Jquery,Html,Truncate,文件内容似乎截断了我的字符串变量 HTML PHP 在发送GET请求时,需要使用URL编码的数据。 请参阅以了解如何操作。如果要传递GET,则需要对字符串进行URL编码,例如load(“submit.php?var=“.some_function_to_URL_encode(string))我不使用jQuery,因此无法使用正确的URL编码方法。太好了。谢谢你的帮助 <div id="element"> <?php echo file_get_contents("fil

文件内容似乎截断了我的字符串变量

HTML

PHP


在发送GET请求时,需要使用URL编码的数据。
请参阅以了解如何操作。

如果要传递GET,则需要对字符串进行URL编码,例如
load(“submit.php?var=“.some_function_to_URL_encode(string))
我不使用jQuery,因此无法使用正确的URL编码方法。太好了。谢谢你的帮助
<div id="element">
    <?php echo file_get_contents("file.txt"); ?>
</div>
function submitData() {
    var string = $('textarea[name=string]').val();
    $('#element').load("submit.php?var="+string);
    $('textarea[name=string]').val("");
    var height = $('#element')[0].scrollHeight;
    $('#element').animate({
        scrollTop: height
    }, 1000);
    $('textarea[name=string]').focus();
}
$str = nl2br($_GET['var']);
if(empty($str)) {
    $str = "Error: Empty string.";
}
$str .= "<br /><br />";
$delete = $_GET['delete'];
if(isset($delete)) {
    file_put_contents("file.txt", "");
    echo file_get_contents("file.txt");
} else {
    file_put_contents("file.txt", $str.PHP_EOL, FILE_APPEND);
    echo file_get_contents("file.txt");
}
Hello,