将新行添加到动态创建的js文件

时间:2015-07-02 10:50:11

标签: javascript

我使用PHP将多个Javascript文件连接成一个。我需要在添加每个部分之前添加新行并尝试'\ n'但这会抛出一个未知的字符错误。表示新行的正确字符是什么?

file_put_contents($JSfile," /n ");


$jspart = file_get_contents($myfile);
file_put_contents($JSfile,'  '. $jspart  , FILE_APPEND);

2 个答案:

答案 0 :(得分:0)

您可以使用预定义的PHP常量textscan来添加正确的' End Of Line'符号:

PHP_EOL

答案 1 :(得分:0)

仅在代码中使用

$servername = "localhost";
$username = "root";
$password = "P@ssword";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";