With the news script, you can post news on your PHP website without modifying your http page.
The realization of the news script
You need to know:
- Working with a database
- Working with forms
- Working with dates and timestamp.
By combining databases and forms, you can perform most of the common scripts !
You will need to separate your script into pages. You will simply need to :
- A page displaying the various news (usually this is the home page)
- A page for writing your news (is therefore a page containing a form for entering these news)
- Inserting a page news in your database.
The news script in PHP consists of two major parts:
-The display news: this script will show by example the last five news on your homepage. This is a very simple script to achieve: a query in the database. In general, the display of news is in the host file of your site (index.php).
- Administration: It includes two PHP pages from which you can add, modify, delete news. These pages should be protected by .htaccess to prevent anyone can have fun writing news.
Finally you must know three little functions that we need to think about using: nl2br, addslashes and stripslashes.
- nl2br: used to save you typing the line breaks in HTML.
- addslashes: in fact, it is not always required to use this feature depending on your web host. But it is better to take the good habit of using it. So before recording the title and content of the news, you apply them addslashes.
- stripslashes: This function does the opposite. Use it just before the title display and content of the news to avoid that one way backslash.
You will especially need these features in the page that displays the news to your visitors ( index.php ) . Keep in mind when you write a news item that you can type HTML.
For all informations about php development, click here !