成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? PHP:fwrite()的用法_Filesystem函數(shù)
全站頭部文字 我要出現(xiàn)在這里
PHP:fwrite()的用法_Filesystem函數(shù) 784 2023-12-15   

fwrite

(PHP 4, PHP 5)

fwrite — 寫入文件(可安全用于二進(jìn)制文件)

說明

int fwrite ( resource $handle , string $string [, int $length ] )

fwrite()string 的內(nèi)容寫入 文件指針 handle 處。

參數(shù)

handle

文件系統(tǒng)指針,是典型地由 fopen() 創(chuàng)建的 resource(資源)。

string

The string that is to be written.

length

如果指定了 length,當(dāng)寫入了 length 個字節(jié)或者寫完了 string 以后,寫入就會停止,視乎先碰到哪種情況。

注意如果給出了 length 參數(shù),則 magic_quotes_runtime 配置選項將被忽略,而 string 中的斜線將不會被抽去。

返回值

fwrite() 返回寫入的字符數(shù),出現(xiàn)錯誤時則返回 FALSE

注釋

Note:

Writing to a network stream may end before the whole string is written. Return value of fwrite() may be checked:

<?php
function fwrite_stream($fp, $string) {
    for ($written = 0; $written < strlen($string); $written += $fwrite) {
        $fwrite = fwrite($fp, substr($string, $written));
        if ($fwrite === false) {
            return $written;
        }
    }
    return $written;
}
?>

Note:

在區(qū)分二進(jìn)制文件和文本文件的系統(tǒng)上(如 Windows) 打開文件時,fopen() 函數(shù)的 mode 參數(shù)要加上 'b'。

Note:

If handle was fopen()ed in append mode, fwrite()s are atomic (unless the size of string exceeds the filesystem's block size, on some platforms, and as long as the file is on a local filesystem). That is, there is no need to flock() a resource before calling fwrite(); all of the data will be written without interruption.

Note:

If writing twice to the file pointer, then the data will be appended to the end of the file content:

<?php
$fp = fopen('data.txt', 'w');
fwrite($fp, '1');
fwrite($fp, '23');
fclose($fp);

// the content of 'data.txt' is now 123 and not 23!
?>

范例

Example #1 一個簡單的 fwrite() 例子

<?php
$filename = 'test.txt';
$somecontent = "添加這些文字到文件n";

// 首先我們要確定文件存在并且可寫。
if (is_writable($filename)) {

    // 在這個例子里,我們將使用添加模式打開$filename,
    // 因此,文件指針將會在文件的末尾,
    // 那就是當(dāng)我們使用fwrite()的時候,$somecontent將要寫入的地方。
    if (!$handle = fopen($filename, 'a')) {
         echo "不能打開文件 $filename";
         exit;
    }

    // 將$somecontent寫入到我們打開的文件中。
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "不能寫入到文件 $filename";
        exit;
    }

    echo "成功地將 $somecontent 寫入到文件$filename";

    fclose($handle);

} else {
    echo "文件 $filename 不可寫";
}
?>

參見

fread() - 讀取文件(可安全用于二進(jìn)制文件) fopen() - 打開文件或者 URL fsockopen() - 打開一個網(wǎng)絡(luò)連接或者一個Unix套接字連接 popen() - 打開進(jìn)程文件指針 file_get_contents() - 將整個文件讀入一個字符串


主站蜘蛛池模板: 高锰酸盐指数和cod的关系| 黑之教室| 掐脖子自制短视频| 山口小夜子| 龙在少林| 拔萝卜电影| 普及的意思三年级下册语文| 女生被打屁股的视频| 十一个月宝宝发育标准| barbapapa| 双生姐妹| 高地1—36集电视剧免费观看剧情| 张耀扬个人资料简介| 米莎巴顿| 张柏芝惊艳照片| 李美琪主演的电影| 孕期体重增长参照表| 寂静之城| 追捕演员表名单| 日本变态网站| 女攻男受调教道具| 恐怖故事电影| 一句话让老公下面硬| 阴阳界 电影| 章子怡和郭富城的吻戏| 莫比乌斯电影在线观看全集高清| 沟通能力自我评价| 赤月| 一夜风流| 后悔造句二年级| 兰陵王电影| 拇指姑娘故事完整版| 火烈鸟电影完整版视频| 黑暗女监日本电影完整版叫什么| 陈瑞的情债| 漂亮主妇 电视剧| 男孩变女孩tg动画| 纵横四海国语免费观看| 搜狐手机网首页新闻| 吃甜品视频| 情侣野战|

?。?!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103