[SOLVED] Stupid Window's Line Feed Crap!
Posted: Tue Aug 31, 2004 10:25 pm
Ok, this is probably gonna get me the Dunce Award For September but I have already wasted a day on it and I am loathe to cut and paste this file (although if I have to I have to, it will just be hard to do it through teary eyes
)
Now, I have an XLS file with around 10k+ groups of lines like this
I want to move it into a format like this
Now let's pretend that the double spaces are tabs. The code I have written actually gives me this
Hence the name of this topic. The code I have written is here. I converted the XLS file into a tab delimited text file first of course.
I have tried a days worth of crap to try to get rid of the line feeds and I am now willing to suffer humiliation for the answer.
So go ahead people's do your best!
At answering that is, not the humiliation bit. 
Now, I have an XLS file with around 10k+ groups of lines like this
Code: Select all
Matthew Overington
Technical Editor
APC Magazine
Ph: +61 2 9288 9123
Fax: +61 2 9267 4909
Web: moverington@apcmag.comCode: Select all
Matthew Overington Technical Editor APC Magazine Ph: +61 2 9288 9123 Fax: +61 2 9267 4909 Web: moverington@apcmag.comCode: Select all
Matthew Overington
Technical Editor
APC Magazine
Ph: +61 2 9288 9123
Fax: +61 2 9267 4909
Web: moverington@apcmag.comCode: Select all
<?php
function nametitleorgphfaxemail($farray)
{
if (!$handle = fopen("dbtext.txt", 'a'))
{
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, stripcslashes($farray[0])."\t".stripcslashes($farray[1])."\t".stripcslashes($farray[2])."\t".stripcslashes($farray[3])."\t".stripcslashes($farray[4])."\t".stripcslashes($farray[5])."\n") === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
}
$lines = file('source.txt');
$i = 0;
$count = 1;
$tarray = array();
foreach ($lines as $line_num => $line)
{
if (strlen($line) > 2)
{
$tarray[$i] = $line;
$i++;
}
else
{
if ((substr($tarray[3],0,3) == "Ph:")&&(substr($tarray[4],0,4) == "Fax:")&&(substr($tarray[5],0,4) == "Web:"))
{
nametitleorgphfaxemail($tarray);
}
else
{
for($j = 0; $j < count($tarray); $j++)
{
echo($tarray[$j]."<br>");
}
echo("<br>");
}
$i = 0;
$tarray = array();
}
}
?>So go ahead people's do your best!