Well, we finally have to deal with data storage, please forgive me to skip a lot of basic knowledge, is really a practical practice to wait ~ ~ Haha!
Simple message board, relying on TXT to store data, just an exercise. Next, let's start with the database, this post is just a warm-up.
Look at the effects and source code:
<?php/** * Simple Message board */$filename = "Message.txt"; Write//If the user commits, writes to the file, writes if (Isset ($_post[' Dosubmit ')) in a certain format {$mess = "{$_post[' username ']}| |". Time (). "| | {$_post[' title ']}| | {$_post[' content '} [n] "; Writemessage ($filename, $mess); } function Writemessage ($filename, $mess) {$fp = fopen ($filename, "a"); Fwrite ($fp, $mess); Fclose ($FP); }//Read if (file_exists ($filename)) {//If the file exists Readmessage ($filename); } function Readmessage ($filename) {$mess = file_get_contents ($filename);//file_get_contents () reads the entire file into a string $mess = RTrim ($mess, "[n]"); The RTrim () function removes whitespace characters or other predefined characters to the right of the string $arrmess = Explode ("[n]", $mess); The explode () function breaks the string into arrays of foreach ($arrmess as $m) {list ($username, $date, $title, $content) = Explode ("| | |" , $m); The list () function is used to assign a set of variables in a single operation echo "<b>{$username}</b>". Date ("Y-m-d h:i"). " {$title},{$content}<br>
The above is the Android programmer to learn PHP development (26)-Simple message Board-phpstorm content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!