Ken Robinson wrote:
Kenneth wrote:
No Ken, you were missing and end bracket.
Anyway here is what I have so far. It is working now but I think it
takes too much resources. Let me know if you can improve the following
code somehow.
-----------------------------------------------------------------------------------------
//Search for the file
$key = "</members>";
//load file into $fc array
$fc=file("members.xml");
//open same file and use "w" to clear file
$f=fopen("members.xml","w");
//loop through array using foreach
foreach($fc as $line)
{
if (!strstr($line,$key)) //look for $key in each line
fputs($f,$line); //place $line back in file
}
fclose($f);
-------------------------------------------------------------------------------------------------
The problem is that I have to file() which I heard takes up to much
resources, but it works. Can I replace the code somehow?
Ken Robinson wrote:
Kenneth wrote:
Ken, I tried your code. Everything fits logically but i keep getting
following error message;
Parse error: syntax error, unexpected ')', expecting ';' in
c:\Inetpub\wwwroot\final\test\lastline.php on line 13
I (obviously) had a few typo's in the code I posted. It should read:
<?
$inp = file('yourfile.name');
$out = fopen('yourfile.name','w');
for ($i=0;$i<count($inp)-1;$i++)
fwrite($out,$inp[$i]);
fclose($out);
?>
You should always take any code posted with a grain of salt and don't
just copy it verbatim. Always check for errors in both the syntax and
logic.
Ken