i have a text file with multiple lines
when a user registers on my site, i want it to say if the username is in use or not
so, i was wondering if there was a piece of script that checks the start of A line in the text file (if a line in the text file starts with "whatever" then echo username already in use)
in the text file it says:
userpass = bobbob (Username: bob, Password:bob)
Dave
Check line starting with...
Moderator: General Moderators
it would probably be easier to delimit your textfile with a comma or a tab... then it would be a matter of exploding one line at a time and checking to see if the username is there
if your txt file looks like this:
bob,bob
fred,password
bill,drowssap
you could read it like this:
if your txt file looks like this:
bob,bob
fred,password
bill,drowssap
you could read it like this:
Code: Select all
$txt_file = fopen("file.txt", "rb");
while($file_line = fgets($txt_file)){
$line_array = explode(",", $file_line);
$username = $line_array[0];
if($register_name == $username){
print"That name is taken!";
}
}Indeed. My classic way of organizing data within text files is:
-Each item seperated by //
-Each line seperated by \r\n (windows) or \n (*nix)
I dislike anything besides the double slashes because how often is it used within data compared to commas, or etc. But everyone has their own favorite, this just happens to be mine.
-Each item seperated by //
-Each line seperated by \r\n (windows) or \n (*nix)
I dislike anything besides the double slashes because how often is it used within data compared to commas, or etc. But everyone has their own favorite, this just happens to be mine.