fwrite() function in PHP


The fwrite() function writes to an open file. It returns the number of bytes written on success, whereas returns False on failure.

Syntax

fwrite(file_pointer, string, length)

Parameters

  • file_pointer − A file system pointer created using fopen(). Required.

  • string − The string to be written. Required.

  • length − Maximum number of bytes to be written. Optional.

Return

The fwrite() function returns the number of bytes written on success, whereas returns False on failure.

Example

<?php
   $file_pointer = fopen("new.txt","w");
   echo fwrite($file_pointer,"This is test string!");
   fclose($file);
?>

Output

20

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

254 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements