[SOLVED] Stupid Window's Line Feed Crap!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

[SOLVED] Stupid Window's Line Feed Crap!

Post by Paddy »

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 :cry: )

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.com
I want to move it into a format like this

Code: Select all

Matthew Overington  Technical Editor  APC Magazine  Ph: +61 2 9288 9123  Fax: +61 2 9267 4909  Web: moverington@apcmag.com
Now let's pretend that the double spaces are tabs. The code I have written actually gives me this

Code: Select all

Matthew Overington
	Technical Editor
	APC Magazine
	Ph: +61 2 9288 9123
	Fax: +61 2 9267 4909
	Web: moverington@apcmag.com
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.

Code: 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();
		}
	}
?>
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! :lol: At answering that is, not the humiliation bit. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you may want to try [php_man]trim[/php_man] instead of stripcslashes..
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

You know, I tried everything EXCEPT trim. I have used trim many times before and I thought it only trimmed whitespace.

Many thanks feyd. Of course, the above was all just a test to see if you guys are still on the ball. I am honestly not as stupid as I seem, honestly.

;)
Post Reply