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
https://forums.phpfreaks.com/topic/48294-commenting-php-codes/
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
https://forums.phpfreaks.com/topic/48294-commenting-php-codes/#findComment-236085
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
https://forums.phpfreaks.com/topic/48294-commenting-php-codes/#findComment-236102
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.