Jump to content

Loop thru and Append String > Front & Back


trochia

Recommended Posts

This post is based on the following [solved] thread, and as requested...shall be opened in a new topic.

 

// http://www.phpfreaks.com/forums/index.php?topic=145174

 

Object:

 

  I have quite a few files, in both .txt (delimited by \n ) and *.csv files I would like to append to both the front of the string, and also at the end of the string.

 

  Some, I would like to do both at the same time, but if I may get the example clarified... i think I will be able to create the functions properly.

 

Present Code:

$myFile = "testFile.txt"; //assign variable to the file to work on
$fh = fopen($myFile, 'r') or die("Can't open file"); 
//$theData = fread($fh, filesize($myFile)); //1 char = 1 byte. or get all with file size
$theData = fgets($fh); // reads to the first new line \n"
fclose($fh);

// Echo to screen the contents
echo $theData;

 

  But where I am lost in then trying to apply (from other thread)

 

As I need to "look to the newlin, and do my actions either appending to the front or the back...

 

//Get for appending
//$tmp = ''; //Create Variable to store pulled array
//for ($i = 0; $i < $appendString; $i = $i + 1)
//  $
//fclose($appendString); // Close the file

 

Thx all for looking,

 

jim

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/138737-loop-thru-and-append-string-front-back/
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.