Page 1 of 1
Read from file TXT
Posted: Wed Mar 02, 2005 4:12 pm
by Vladinator
What script can I use, if I want php to read from a small txt file.
Like, if the file looks like this:
Code: Select all
name=Hans
password=something
email=some@one.com
How can I make the php get the name, like, get the text after "name=", "password=" and "email="?
Posted: Wed Mar 02, 2005 4:20 pm
by feyd
untested
Code: Select all
preg_match_all('#^\s*(.*?)\s*=\s*(.*?)\s*$#m', file_get_contents($filename), $matches);
print_r($matches);
Posted: Wed Mar 02, 2005 4:52 pm
by Vladinator
Worked!
Now, I just get this in the HTML code:
Code: Select all
Array
(
ї0] => Hans
ї1] => something
ї2] => some@one.com
)
What script can I now use, to get the array 0 (Hans), 1 (something) and 2 (
some@one.com)?
Using this script to display that information:
Code: Select all
$filename = '\accounts\hans';
$fp = fopen($filename,'r');
preg_match_all('#^\s*(.*?)\s*=\s*(.*?)\s*$#m', file_get_contents($filename), $array);
print_r($arrayї2]);
Posted: Wed Mar 02, 2005 4:55 pm
by Vladinator
Found it out, tnx for help!
Used:
Code: Select all
print_r($arrayї'2']ї'0']);
print_r($arrayї'2']ї'1']);
print_r($arrayї'2']ї'2']);
Posted: Wed Mar 02, 2005 5:10 pm
by Vladinator
Oh, last quest, how can i fix this?
Code: Select all
if($username=="$got_name" AND $password==print_r($arrayї2]ї0])) {
Aaa... tried to make it like this:
Code: Select all
$pass = print_r($arrayї2]ї0]);
if($username=="$got_name" AND $password==$pass) {
But that did not work, the $pass just echoes the text, it does not keep it like a variable... :S
Posted: Wed Mar 02, 2005 5:23 pm
by feyd
...

Posted: Wed Mar 02, 2005 6:20 pm
by timvw
Posted: Wed Mar 02, 2005 6:26 pm
by Vladinator
Fixed it, finnaly!

Tnx, and good night, 01:20!!!