User writes to (.txt) file-PHP source code

Source: Internet
Author: User
Php code written into (.txt)

/* Check whether the user nickname is repeated * parameter $ user is the login user's nickname * When the returned value is true, when the nickname is available * When the returned value is false, nickname unavailable */function chklogin ($ file, $ user) {$ boo = false; if (file_exists ($ file) {$ userarr = file ($ file ); /* determine whether the nickname is repeated */foreach ($ userarr as $ value) {$ tmparr = explode ('#', $ value ); if ($ user = $ tmparr [0]) {$ boo = true; break ;}} return $ boo ;} /* write the nickname of the logged-on user to the file * save format: nickname # ip # logon time * $ file: save file address * $ user: nickname * $ ip: logon IP address * $ sex: Gender */function addlogin ($ file, $ User, $ ip, $ sex) {$ tmp = $ user. '#'. $ ip. '#'. $ sex. chr (13 ). chr (10); $ fp = fopen ($ file, 'A'); $ boo = fwrite ($ fp, $ tmp); fclose ($ fp ); return $ boo;}/* convert the user list to an array * $ file: User list file */function storeuser ($ file) {$ tmparr = file ($ file ); $ userarr = array (); foreach ($ tmparr as $ value) {$ tmparr = explode ('#', $ value); $ userarr [] = $ tmparr [0]. ','. $ tmparr [2];} return $ userarr;}/* write the speech content to the file * $ file: Save the file address * $ mess: save the content */function ad Dmess ($ file, $ mess) {$ fp = fopen ($ file, 'A'); $ boo = fwrite ($ fp, $ mess. chr (13 ). chr (10); fclose ($ fp); return boo;}/* delete the user in the file * $ file: Save the file address * $ user: user to be deleted */function deluser ($ file, $ user) {$ tmparr = file ($ file); $ rearr = array (); foreach ($ tmparr as $ value) {$ tmp = explode ('#', $ value); if ($ tmp [0]! = $ User) {$ rearr [] = $ value ;}}$ fp = fopen ($ file, 'W + '); foreach ($ rearr as $ value) {fwrite ($ fp, $ value) ;}fclose ($ fp );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.