略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: fputs

2024-12-22

fputs

(PHP 4, PHP 5, PHP 7, PHP 8)

fputsfwrite() 的别名

说明

此函数是该函数的别名:fwrite()

add a noteadd a note

User Contributed Notes 2 notes

up
-4
Anonymous
21 years ago
You can use here-documents in PHP but not for printing to a file pointer.

There's a lot to say on them so just go to the page: http://www.php.net/manual/language.types.string.php
up
-10
rembert at floating-point dot nl
19 years ago
Adding to Adam (Nedstat):
fputs without the length parm just writes all data up to but not including the first 0 byte it encounters.

Therefore fputs($fp,"hello\0world") will only write hello to $fp whereas
fputs($fp,"hello\0world",11) will write both words.

If this doesn't make sense for you, remember strings are always terminated with that 0 byte. Binary data doesn't have such a terminator byte as a 0 byte can be a completely valid piece of data therefore you always need to know the length of the binary datapart.

BTW strlen() is binary safe, so you can use that to get the length of the binary data part as well - this is different from C which counts the number of chars up to the 0 byte. So the example above could also be written as:

fputs($fp,"hello\0world",strlen("hello\0world"))

官方地址:https://www.php.net/manual/en/function.fputs.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3