Page 1 of 1

Posted: Wed Mar 19, 2003 6:28 pm
by romeo
I have a text file that has sections of any number of lines split with a double space \n\n\n

so it goes

Code: Select all

name phone number
descriptions shdfhdfhdf
fdghdhfdhdfghdh
fdhdfhdghdhdhdhfghjj
dfjfdjdfjdjdjd


name phone number
descriptions shdfhdfhdf
fdghdhfdhdfghdh


name phone number
descriptions shdfhdfhdf
fdghdhfdhdfghdhhdfhdf
fdghdhfdhdfghdhhdfhdf
fdghdhfdhdfghdhhdfhdf
fdghdhfdhdfghdhhdfhdf
fdghdhfdhdfghdhhdfhdf
fdghdhfdhdfghdhhdfhdf
fdghdhfdhdfghdhhdfhdf
fdghdhfdhdfghdh


name 724 838 7526
blah

How do i split this mess up into variable so I can get
$NAME, $PH ONE, $DESCRIPTION
$NAME, $PH ONE, $DESCRIPTION
$NAME, $PH ONE, $DESCRIPTION
$NAME, $PH ONE, $DESCRIPTION



I am at the end of my rope, I need to get btter with expressions i assume ;)

Posted: Wed Mar 19, 2003 10:08 pm
by romeo
I am trying this... logic is there.. actual crap not working

Code: Select all

<?
$file = file("test1.txt"); 
$file = explode("\n\n", $file);
while(list(,$value)=each($file)) &#123;
list($line1,$line2)=explode("\n", $value);
list($1a, $1b)=explode(" ", $line1);

print("$line1 $line2");
&#125;
?>

Posted: Thu Mar 20, 2003 8:32 am
by romeo
I'm more than willing to send exact txt file and code to anyone who can help... it's driving me insane..

a problem (not the only problem)
is that NAME is one word where NUMBER is a ton of words or strings. then a /n the DESCRIPTS (many lines and words)

bump

Posted: Fri Mar 21, 2003 2:42 pm
by romeo
bumpidee bump bump bumpidee bump bump lok at frosty go

Posted: Fri Mar 21, 2003 7:56 pm
by volka
$file = file("test1.txt");
the contents of the file is already split into single lines. Try http://www.php.net/manual/de/function.fread.php instead.

Posted: Fri Mar 21, 2003 9:12 pm
by romeo
THANK YOU SO MUCH FOR REPLYING

its still not working tho... gettinga
" Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/httpd/vhosts/h.com/httpdocs/images/conv.phtml on line 11 "

this is what i got, any help?


Code: Select all

<?
// get contents of a file into a string
$filename = "text1.txt";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));


$file = explode("\n\n", $contents);
while(list(,$value)=each($file)) 
&#123;
list($line1,$line2)=explode("\n", $value);
list($1a, $1b)=explode(" ", $line1);

print("$line1 $line2");
&#125;

fclose ($handle);
?>

Posted: Sat Mar 22, 2003 12:32 am
by volka
$1a, $1b
variable-names must not begin with a number

Posted: Sat Mar 22, 2003 7:29 am
by romeo
LOFL, Im an idiot! Please don't agree publicly ;)


Im having aa problem tho.. I want line was to read the first word and then feed the rest of the line into the seocnd variable, right now im SPLIT at the " " but the rest of the line has spaces also... anyway to only split at the first " "