Jump to content
xisto Community
Sign in to follow this  
iGuest

Php Reading And Writing To File the code is very esay

Recommended Posts

this code to
Read from file
you can use this code in to make a small data base
and it is very to use

$fp = fopen ("file.txt", "r"); $bytes = 4; $buffer = fread($fp, $bytes); fclose ($fp); print $buffer;

-------------------
to write to same file

$fp = fopen ("file.txt", "w+"); fwrite ($fp, "Test"); fclose ($fp);

----------------
thanks and iwait the commant
Edited by microscopic^earthling (see edit history)

Share this post


Link to post
Share on other sites

For reading a file, this is much easier

 

$filedata = file_get_contents('filename.txt');

This function was implemented in PHP 4+ i think.

<{POST_SNAPBACK}>


Tip: You can use a URL as a filename with this function if the fopen wrappers have been enabled.

 

<?

$dp = "http://www.vaila.net/v1/home.php;;

if (!$dp)

{

echo("<P>Error: unable to load URL file into $dp. Process aborted.</P>");

exit();

}

$sp = file_get_contents($dp);

highlight_string($sp);

?>

Share this post


Link to post
Share on other sites

i implement this

<?$fp = fopen('data.txt', 'r');

if ($fp) {
  while (!feof($fp)) {
      $texts = fread($fp, 4096);
  echo 'this is -> ' . $texts . '\n <br?';
  }
  fclose($fp);
}

?>


for the data file:

data.txtsatu@mon.com,
combo@bakso.com,
special@monyong.com,
kuya.batok@forever.and.ever.com,
special.pake.telor.2@tolong.jangan.lama.com


the result :

this is -> satu@mon.com combo@bakso.com special@monyong.com kuya.batok@forever.and.ever.com special.pake.telor.2@tolong.jangan.lama.com \n

what i want is
can it read line by line ?
no matter how long the line is

danke

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.