[PHP] explode, split, or what?

2003-06-19 Thread Kyle Babich
Thank you to those of you who helped me with my last problem earlier today.

Now I have a text file (setup.txt) that has a series of values all seperated by 
\r\n's.  Inside of another file I'm trying to read setup.txt into $rawSetupData and 
explode that with \r\n's into an array called $setupData.  My problem is that the 
explode function doesn't seem to be doing anything, and neither is split which I tried 
also.  Here is my code:

setup.txt
***
John\'s X Log
10
5
example.com
treeclimber56
ab3c45def
***

test.php
***
?php

if (file_exists(setup.txt)) {
$rawSetupData = readfile(setup.txt);
$setupData = explode(\r\n, $rawSetupData);
echo $setupData[0];
}
else echo Error opening \setup.txt\;

?
***

Actual results of running test.php
***
John\'s X Log 10 5 example.com treeclimber56 ab3c45def 61
***

Desired reults of running test.php
***
John's X Log
***

Other problem:
In the actual results of running test.php where is the 61 coming from?

Thank you,
--
Kyle

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] explode, split, or what?

2003-06-19 Thread Sævar Öfjörð


why don't you just do this?

***
?php
if(file_exists(setup.txt)){
  $lines=file(setup.txt);
  echo stripslashes($lines[0]);
}
else echo Error opening \setup.txt\;
?
***

file() returns the file in an array, each line as new value, so line nr.
1 is $line[0], line nr. 2 is $line[1] etc...
I added stripslashes() on the output so that you won't get John\'s X
Log


Sævar - ICELAND


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] explode, split, or what?

2003-06-19 Thread Steve Keller
At 6/19/2003 10:41 PM, Kyle Babich wrote:

 Inside of another file I'm trying to read setup.txt into $rawSetupData 
and explode that with \r\n's
 into an array called $setupData.

Why on earth?

http://us4.php.net/file

 ?php

 if (file_exists(setup.txt)) {
$rawSetupData = readfile(setup.txt);
$setupData = explode(\r\n, $rawSetupData);
echo $setupData[0];
 }
 else echo Error opening \setup.txt\;

 ?
No no nonono

?
if ($file_exists(setup.txt)) {
$setupData = file(setup.txt);
}
else {
echo 'Error opening setup.txt';
}
?
--
S. Keller
UI Engineer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Pkwy.
Anchorage, AK 99508
907.770.6200 ext.220
907.336.6205 (fax)
Email: [EMAIL PROTECTED]
Web: www.healthtvchannel.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php