Page 1 of 1
detect new line in php?
Posted: Thu Aug 04, 2005 8:55 pm
by potato
Hi everybody,
i got a text-file wich i want to explode.
How can i detect a new line int the text file?
text look like this:
line1line1line1line1line1line1line1
line2line2line2line2line2line2line2
line3line3line3line3line3line3line3
etc...
so there's no /n or something, just plain text
many thanx in advance
tom
Posted: Thu Aug 04, 2005 8:57 pm
by timvw
If there isn't a \n then there isn't a new line...
Do the lines have a fixed width?
Posted: Thu Aug 04, 2005 9:07 pm
by potato
nope, just a text file with some text.
this is my explode code:
Code: Select all
include 'testfeed.php';
$pizza = explode("/n", $text); //opdelen
$aantal = count($pizza); //aantal pizzas tellen
in the testfeed.php file i have put the whole text in $text.
My result is the whole text itself.
Posted: Thu Aug 04, 2005 9:11 pm
by feyd
uh.. backslash.. not forward slash..
Posted: Thu Aug 04, 2005 9:11 pm
by trdesigns
If I'm not mistaken, the text-file that you have will be interpreted as follows:
Code: Select all
line1line1line1line1line1line1line1\n
line2line2line2line2line2line2line2\n
line3line3line3line3line3line3line3\n
So you should have no trouble using the split() function:
Code: Select all
$file_contents=file_get_contents("file.txt");
$file_lines=split("/\n",$file_contents);
The above will get you an array $file_lines with the lines as elements
Hope this helps.

Posted: Thu Aug 04, 2005 9:13 pm
by feyd
why not just use
file() ??
Posted: Thu Aug 04, 2005 9:13 pm
by potato
thankyou
