Dear group,
I am a beginner in php and I was little bit experience in C language.
I
want to read a file's content and delete the first line of the file and
display those lines which has got deleted.
The content of the external file , which is in .cvs format is:
-------------------------------------------------------------------
Agency,Ebook,Da te,Sold#,Sold$, Refund#,Refund$ ,GAW#,GAW$,Inco me
cbezy,Dog,8/7/06,0,0,0,0,204, 16.88,-16.88
cbezy,CMS,8/7/06,1,10.79,0,0, 0,0,10.79
cbgeo,Sudoku,8/7/06,1,14.72,0,0, 0,0,14.72
cbgeo,Cock,8/7/06,1,14.72,0,0, 0,0,14.72
ppgeo,Sudoku,8/7/06,17,229.58,2, 24.16,2286,118. 62,86.8
ppgeo,Pythons,8/7/06,1,19.36,0,0, 250,8.84,10.52
ppgeo,Cockatiel s,8/7/06,9,108.46,1,1 6.21,0,0,92.25
ppgeo,Cockatoos ,8/7/06,5,72.66,0,0, 743,47.56,25.1
ppgeo,Wastewate r,8/7/06,1,44.87,0,0, 49,5.25,39.62
ppgeo,Chinchill as,8/7/06,1,6.91,0,0,0 ,0,6.91
ppgeo,Modhomes, 8/7/06,0,0,0,0,189, 99.94,-99.94
ppgeo,Smormonsu b,8/7/06,1,3.54,0,0,0 ,0,3.54
--------------------------------------------------------------------
The small program which I wrote is
<?php
function read_file($fnam e)
{
$f = fopen($fname,"r ");
if(!$f)
die("file does not exist");
$buff = fread($f,filesi ze($fname));
if(!$buff)
die("file reading failed");
return $buff;
}
function parse_condent($ buff,$fname)
{
$f = fopen($fname, "a+");
if(!$f)
die("file does not exist");
if($buff == '\n' || $buff == '\r' || $buff == '\t') /*####*/
unset($buff);
return $buff;
}
$f = read_file("1.cs v");
echo $f.'<brbefore delition <br>';
$p = parse_condent($ f,"1.csv");
echo $p.'<brAfter deletion';
?>
when the line marked with /*####*/ is taken then the whole array is
getting
deleted. I want the specified line and chars. Any help or url link is
appreciated.
<OT>
In C programming the string, which is a pointer is iterated and
checked with
a specified pattern. How is that possible in php?
</OT>
I am a beginner in php and I was little bit experience in C language.
I
want to read a file's content and delete the first line of the file and
display those lines which has got deleted.
The content of the external file , which is in .cvs format is:
-------------------------------------------------------------------
Agency,Ebook,Da te,Sold#,Sold$, Refund#,Refund$ ,GAW#,GAW$,Inco me
cbezy,Dog,8/7/06,0,0,0,0,204, 16.88,-16.88
cbezy,CMS,8/7/06,1,10.79,0,0, 0,0,10.79
cbgeo,Sudoku,8/7/06,1,14.72,0,0, 0,0,14.72
cbgeo,Cock,8/7/06,1,14.72,0,0, 0,0,14.72
ppgeo,Sudoku,8/7/06,17,229.58,2, 24.16,2286,118. 62,86.8
ppgeo,Pythons,8/7/06,1,19.36,0,0, 250,8.84,10.52
ppgeo,Cockatiel s,8/7/06,9,108.46,1,1 6.21,0,0,92.25
ppgeo,Cockatoos ,8/7/06,5,72.66,0,0, 743,47.56,25.1
ppgeo,Wastewate r,8/7/06,1,44.87,0,0, 49,5.25,39.62
ppgeo,Chinchill as,8/7/06,1,6.91,0,0,0 ,0,6.91
ppgeo,Modhomes, 8/7/06,0,0,0,0,189, 99.94,-99.94
ppgeo,Smormonsu b,8/7/06,1,3.54,0,0,0 ,0,3.54
--------------------------------------------------------------------
The small program which I wrote is
<?php
function read_file($fnam e)
{
$f = fopen($fname,"r ");
if(!$f)
die("file does not exist");
$buff = fread($f,filesi ze($fname));
if(!$buff)
die("file reading failed");
return $buff;
}
function parse_condent($ buff,$fname)
{
$f = fopen($fname, "a+");
if(!$f)
die("file does not exist");
if($buff == '\n' || $buff == '\r' || $buff == '\t') /*####*/
unset($buff);
return $buff;
}
$f = read_file("1.cs v");
echo $f.'<brbefore delition <br>';
$p = parse_condent($ f,"1.csv");
echo $p.'<brAfter deletion';
?>
when the line marked with /*####*/ is taken then the whole array is
getting
deleted. I want the specified line and chars. Any help or url link is
appreciated.
<OT>
In C programming the string, which is a pointer is iterated and
checked with
a specified pattern. How is that possible in php?
</OT>
Comment