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