首頁  >  文章  >  後端開發  >  簡單的php留言本範例溫習

簡單的php留言本範例溫習

WBOY
WBOY原創
2016-07-28 08:29:111064瀏覽

先寫前端:寫在10.html頁面

<code><span><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></span><span><<span>html</span><span>xmlns</span>=<span>"http://www.w3.org/1999/xhtml"</span><span>lang</span>=<span>"zh-CN"</span>></span><span><<span>head</span>></span><span><<span>meta</span><span>http-equiv</span>=<span>"Content-Type"</span><span>content</span>=<span>"text/html; charset=UTF-8"</span>></span><span><<span>title</span>></span>10<span></<span>title</span>></span><span><<span>meta</span><span>name</span>=<span>"description"</span><span>content</span>=<span>""</span> /></span><span></<span>head</span>></span><span><<span>body</span>></span><span><<span>form</span><span>action</span>=<span>"10.php"</span><span>method</span>=<span>"post"</span>></span><span><<span>input</span><span>type</span>=<span>"text"</span><span>name</span>=<span>"title"</span>/></span><span><<span>input</span><span>type</span>=<span>"text"</span><span>name</span>=<span>"content"</span>/></span><span><<span>input</span><span>type</span>=<span>"submit"</span> /></span><span></<span>form</span>></span><span></<span>body</span>></span><span></<span>html</span>></span></code>

10.php 想txt文字中寫入內容

<code><span><?php</span><span>$str</span>=<span>$_POST</span>[<span>'title'</span>].<span>','</span>.<span>$_POST</span>[<span>'content'</span>]. <span>"\n"</span>;

<span>$fh</span>=fopen(<span>'1.txt'</span>, <span>'a'</span>);

fwrite(<span>$fh</span>, <span>$str</span>);

fclose(<span>$fh</span>);

<span>echo</span><span>"ok"</span>;


 <span>?></span></code>

msg.php 留言本標題清單頁

<code><span><span><?php</span>    header(<span>"Content-Type:text/html;charset=utf8"</span>);

    <span>$fh</span>=fopen(<span>'1.txt'</span>, <span>'r'</span>);

    <span>$i</span>=<span>1</span>;

    <span>while</span> ((<span>$str</span> = fgetcsv(<span>$fh</span>))!=<span>false</span>) {
        <span>echo</span><span>'<li><a href="msgtid.php?tid='</span>,<span>$i</span>,<span>'">'</span>,<span>$str</span>[<span>0</span>],<span>'</a></li>'</span>;

        <span>$i</span>=<span>$i</span>+<span>1</span>;
    }

 <span>?></span></span></code>

redmsg.php 內容頁

<code><span><span><span><?php</span>    header(<span>"Content-Type:text/html;charset=utf8"</span>);

    <span>$fh</span>=fopen(<span>'1.txt'</span>, <span>'r'</span>);

    <span>$i</span>=<span>1</span>;

    <span>while</span> ((<span>$str</span> = fgetcsv(<span>$fh</span>))!=<span>false</span>) {

        <span>if</span> (<span>$i</span>==<span>$_GET</span>[<span>'tid'</span>]) {
            <span>echo</span><span>'<li>'</span>,<span>$str</span>[<span>0</span>],<span>'</li><br/>'</span>;

            <span>echo</span><span>'<li>'</span>,<span>$str</span>[<span>1</span>],<span>'</li><br/>'</span>;
        }
    <span>$i</span>=<span>1</span>+<span>$i</span>;     
    }

 <span>?></span></span></span></code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了 簡單的php留言本範例溫習,包括了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn