LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Best Way to manipulate a text file.. php ? (https://www.linuxquestions.org/questions/programming-9/best-way-to-manipulate-a-text-file-php-617128/)

8rucech85 01-29-2008 08:24 AM

Best Way to manipulate a text file.. php ?
 
I have a tab delimited text file from which i want to compare each successive pair of lines and depending on the result drop one of the lines.

What method would be easiest for this ?

I am running RHE

Example
---------------
a | 10 15
b | 10 13


i want to saw

if col2oflineb > col2oflinea

{
lineb=null;
}

I’m fairly familiar with php but usually doing this with a database not text files...

Any comments would be appreciated

Regards

Bruce

rubadub 01-30-2008 12:19 AM

here's an example, rather messy but it is late...
Code:

<?php
$sa = "a        |        10        15";
$sb = "b        |        10        13";

print "a: '".$sa."'<br>";
print "b: '".$sb."'<br>";

print "<br>\n";

$a = split("        ", $sa);
print_r($a);
$b = split("        ", $sb);

print "<br>\n";

print "Therefore:<br>\n";

$sc = ($a[3] > $b[3]) ? ($sa) : ($sb);
print "c: '".$sc."'<br>";
?>


8rucech85 01-30-2008 04:35 AM

Thanks,

Just what i needed.

Regards


All times are GMT -5. The time now is 04:43 PM.