Jump to content

Commenting PHP codes


boneXXX

Recommended Posts

Could some one comment this codes what they do please? I found it on the web and I want to understand it. Thanks in advance.

 

<?php 
$fname = "test.txt"; 
$exclude = "some string"; 
$lines = file($fname); 
$out = ""; 
foreach ($lines as $line) { 
  if (strstr($line, $exclude) == "") { 
   $out .= $line; 
  } 
} 
$f = fopen($fname, "w"); 
fwrite($f, $out); 
fclose($f); 
?>

Link to comment
Share on other sites

Could some one comment this codes what they do please? I found it on the web and I want to understand it. Thanks in advance.

 

<?php 

//sets the file you want to read
$fname = "test.txt"; 
//excludes a string from the modification
$exclude = "some string"; 
//puts the opened file into array $lines
$lines = file($fname); 
//sets up $out as empty variable
$out = ""; 
//sets up the loop
foreach ($lines as $line) { 
//if it is equal to nothing after the excluded string $out equals the first part of the string
  if (strstr($line, $exclude) == "") { 
   $out .= $line; 
  } 
} 
//reopens the file with write permissions
$f = fopen($fname, "w"); 
//writes the file with the changes that were made above
fwrite($f, $out); 
//closes the file
fclose($f); 
?>

Link to comment
Share on other sites

It is close to what I am looking for but not exactly.

 

I am trying to find a specific line, which starts with a unique word, to delete in a .txt file then rewrite that line. Could you help me on this please ?

 

I am ok till finding the line but don't know how to delete and rewrite it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.