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
Vladinator
Forum Newbie
Posts: 12 Joined: Mon Feb 28, 2005 6:08 pm
Post
by Vladinator » Wed Mar 02, 2005 4:12 pm
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="?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Mar 02, 2005 4:20 pm
untested
Code: Select all
preg_match_all('#^\s*(.*?)\s*=\s*(.*?)\s*$#m', file_get_contents($filename), $matches);
print_r($matches);
Vladinator
Forum Newbie
Posts: 12 Joined: Mon Feb 28, 2005 6:08 pm
Post
by Vladinator » Wed Mar 02, 2005 4:52 pm
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]);
Vladinator
Forum Newbie
Posts: 12 Joined: Mon Feb 28, 2005 6:08 pm
Post
by Vladinator » Wed Mar 02, 2005 4:55 pm
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']);
Vladinator
Forum Newbie
Posts: 12 Joined: Mon Feb 28, 2005 6:08 pm
Post
by Vladinator » Wed Mar 02, 2005 5:10 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Mar 02, 2005 5:23 pm
...
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Wed Mar 02, 2005 6:20 pm
Vladinator
Forum Newbie
Posts: 12 Joined: Mon Feb 28, 2005 6:08 pm
Post
by Vladinator » Wed Mar 02, 2005 6:26 pm
Fixed it, finnaly!
Tnx, and good night, 01:20!!!