Home >php教程 >PHP源码 >PHP 写字符串到文件中

PHP 写字符串到文件中

PHP中文网
PHP中文网Original
2016-05-25 17:14:461478browse

PHP 写字符串到文件中

<?
function write_to_file($fn, $str)
{
    if ($str == &#39;&#39;) return &#39;Nothing to write...&#39;;
    if ($fn == &#39;&#39;) return &#39;No file to write to...&#39;;
    if (($fp = @fopen($fn, &#39;w&#39;)) === false) return &#39;Error obtaining file handle&#39;;
    if (@fwrite($fp, $str, strlen($str)) === false)
    {
        fclose($fp);
        return &#39;Error writing to file&#39;;
    }
    fclose($fp);
    return &#39;Data written to file successfully&#39;;
}
?>


                   

以上就是PHP 写字符串到文件中的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn