| AND OR | string words | *

string handling

|

insert at specific location


lets say you have a file where you want to insert a string into an existing file at a specific location

put a key into the file, where you want the new text appear

i.e.

<--INSERT-->

for this to work this has to be on one line - and on its own

then use this snippet to insert the new data at this keypoint



full source of insert at specific location [ line 1 - 15 ] | download insert at specific location

1    <?php
2   $insert_key '<--INSERT-->';
3   $old_data file('path/to/file');
4   $new_data 'text to write in to the file';
5   for($x=0;$x<count($old_data);$x++)
6   {
7       if(trim($old_data[$x]) != $insert_key)
8       {
9           $string .= $old_data[$x];
10       }else{
11           $string .= $insert_key."n".$new_data."n";
12       }
13   }
14   // write $string to file
15   ?>



19 hits by 9 users in the last 30 minutes.