|
Hello hi
I have a text file that i am trying to insert data into the text file but still maintain the structure of the text file.
function file_get_contents($file) {
$file = file($file);
return !$file ? false : implode('', $file);
}
function implode_assoc($inner_glue, $outer_glue, $array) {
$output = array();
foreach( $array as $key => $item )
$output[] = $key . $inner_glue . $item;
return implode($outer_glue, $output);
}
$hostdata = file_get_contents("http.conf");
$datasplit= split("\n", $hostdata);
//echo $datasplit;
foreach ($datasplit as $rec)
{
if (preg_match("/listen/i", $rec))
{
}
}
This is the code i have so far what happens here is that the data from the file is read into an array then i use the split function to split the data in the array at the end of every line.
Then i go through each line in the array using the foreach command looking for a certain thing in a line. Let say i am looking for the word listen.
What i am triyng to do is after the world listen is found. i go to the next line and enter a data lets say listen 1 2 3 4 5. Then continues to search the array for
listen 2 - when listen 2 is found it will stop again go to a new line and enter data again.
After this data entered in to the arry i need to write the data back into the text file. Please i am asking you to help me with please i need to get this done by atlest friday. That would be great if you dont mind thank you. Very much. If you have any futher question please contact me on aim rcubes85
|