• php file_put_contents() 写入回车


    PHP file_put_contents() 函数是一次性向文件写入字符串或追加字符串内容的最合适选择。

    file_put_contents()

    file_put_contents() 函数用于把字符串写入文件,成功返回写入到文件内数据的字节数,失败则返回 FALSE。

    file_put_contents() 的行为实际上等于依次调用 fopen()fwrite() 以及 fclose() 功能一样。

    在php中,用file_put_contents() 把字符串写入文件时,有时候发现写入的内容不能换行。

    如:

    <?php
    $a = '<?php 
     $a["1"]=a; 
     $a["2"]=b; 
     return $a; 
    ';
    file_put_contents('test.php', $a);
    ?>

    test.php 的结果是:

    <?php $a["1"]=a; $a["2"]=b; return $a;

    内容中没有回车。

    在网上查找解决方法,说是要把输入的内容用""来代替''。试验了下,结果可以。

    <?php
    $a = "<?php 
     $a['1']=a; 
     $a['2']=b; 
     return $a; 
    ";
    file_put_contents('test.php', $a);
    
    ?>
    
    test.php 的结果是:
    
    <?php 
     $a['1']=a; 
     $a['2']=b; 
     return $a; 
  • 相关阅读:
    Node 基本配置
    python GIL锁
    大数据 Zookeeper 集群
    大数据 Hadoop HA
    python 内置方法使用
    Linux Curl使用
    Linux 文件解压缩
    大数据 Hadoop 常见端口
    大数据 Hadoop 集群安装
    css结构设计思想
  • 原文地址:https://www.cnblogs.com/zjfazc/p/3314517.html
Copyright © 2020-2023  润新知