Jump to content

Need help with function


wattee

Recommended Posts

Hello!

Any help would be good.

 

Problem:

I have a simple text file where there's some usual text with commas, spaces and dots lines separated by \n.

 

I have this function:

------------------------------------------------

Line number On/Off | Expand/Contract

 

   1. $sfile = 'test.txt';
   2. function fcontent($sfile)
   3. {
   4.     $fc = file_get_contents($sfile);
   5.     $del = "\n";
   6.     $arr = explode($del, $fc);
   7.     $fp = fopen("log.html", "w+");
   8.    
   9.     foreach($arr as $key => $value)
  10.     {
  11.         fwrite($fp, $value . "\n");
  12.     }
  13. }

 

------------------------------------------------

Point of this function would be then taking file content from text file, putting it in to array and writing it to html file.

Everything works, but as you might guess it's not final.

 

1. The file log.html appears totally w/o any html elements file wich is logical since i haven't added any html elements, this is the 1st task thing i would need help with to insert into html file <table><tr><td></td>Some text here</tr></table>.

 

2. The second aim for this function woul'd be to write to file as an array value.

e.g. <tr><td>. $arr[1] .</td></tr>

So if i had somewhat 5 values each in a different row,

function been executed for the 3rd time, it would look something like this.

Line number On/Off | Expand/Contract

 

   1.  
   2. <tr>
   3. <td>. $arr[11] .</td>
   4. <td>. $arr[12] .</td>
   5. <td>. $arr[13] .</td>
   6. <td>. $arr[14] .</td>
   7. <td>. $arr[15] .</td>
   8. </tr>
   9.  

 

 

I know its alot to ask so if you would at least point me in the right direction i'd be thankful.

Link to comment
https://forums.phpfreaks.com/topic/179964-need-help-with-function/
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.