Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

fwrite function syntax tag tutorial 2013





Alert! Connect with 10,000 Chating Online. Join Now

Php fwrite () function

Write your php code

 
<?php ?>

Php Result


Your code below



(PHP 3, PHP 4 , PHP 5)

fwrite -- Binary-safe file write

Syntax

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

fwrite() writes the contents of string to the file stream pointed to by handle. If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first.

fwrite() returns the number of bytes written, or FALSE on error.

Note that if the length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from string.

Note: On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter.

Example 1. A simple fwrite example

<?php
$filename
= 'test.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    
// In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    
if (!$handle = fopen($filename, 'a')) {
         echo
"Cannot open file ($filename)";
         exit;
    }

    
// Write $somecontent to our opened file.
    
if (fwrite($handle, $somecontent) === FALSE) {
        echo
"Cannot write to file ($filename)";
        exit;
    }
    
    echo
"Success, wrote ($somecontent) to file ($filename)";
    
    
fclose($handle);

} else {
    echo
"The file $filename is not writable";
}
?>

See also fread(), fopen(), fsockopen(), popen(), and file_put_contents().

Php fwrite Function syntax tag

fwrite php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php fwrite syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online