Build Your Own DatabaseDriven Website Using PHP amp;amp; MySQL [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Build Your Own DatabaseDriven Website Using PHP amp;amp; MySQL [Electronic resources] - نسخه متنی

Kevin Yank

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








Putting it all Together

The completed code that will output our joke text (with all special
character, multi-page, and custom tag conversion in place) is as follows.
This file, along with an updated joke listing script (jokelist.php),
and a front page that lets our visitors choose a joke category to view (index.php),
are provided in the code archive.

<!-- joke.php -->
...
// Get the joke text from the database
$id = $_GET['id'];
$joke = mysql_query("SELECT JokeText FROM Jokes
WHERE ID='$id'");
$joke = mysql_fetch_array($joke);
$joketext = $joke['JokeText'];
// Filter out HTML code
$joketext = htmlspecialchars($joketext);
// If no page specified, default to the
// first page ($page = 0)
if (!isset($_GET['page'])) $page = 0;
else $page = $_GET['page'];
// Split the text into an array of pages
$textarray=spliti('[PAGEBREAK]',$joketext);
// Select the page we want
$joketext=$textarray[$page];
// Bold and italics
$joketext = str_replace(
array('[b]','[B]'),'<strong>',$joketext);
$joketext = str_replace(
array('[eb]','[EB]'),'</strong>',$joketext);
$joketext = str_replace(
array('[i]','[I]'),'<em>',$joketext);
$joketext = str_replace(
array('[ei]','[EI]'),'</em>',$joketext);
// Paragraphs and line breaks
$joketext = ereg_replace("r",'',$joketext);
$joketext = ereg_replace("nn",'</p><p>',$joketext);
$joketext = ereg_replace("n",'<br />',$joketext);
// Hyperlinks
$joketext = ereg_replace(
'[L]([-_./a-zA-Z0-9!&%#?+,'=:~]+)[EL]',
'<a href="></a>', $joketext);
$joketext = ereg_replace(
'[L=([-_./a-zA-Z0-9!&%#?+,'=:~]+)]'.
'([-_./a-zA-Z0-9 !&%#?+$,'"=:;~]+)[EL]',
'<a href=">2</a>', $joketext);
$PHP_SELF = $_SERVER['PHP_SELF'];
if ($page != 0) {
$prevpage = $page - 1;
echo("<p><a href="$PHP_SELF?id=$id&page=$prevpage">".
'Previous Page</a></p>');
}
echo( "<p>$joketext</p>" );
if ($page < count($textarray) - 1) {
$nextpage = $page + 1;
echo("<p><a href="$PHP_SELF?id=$id&page=$nextpage">".
'Next Page</a></p>');
}
...

Don't forget to provide documentation so that users of your joke submission
form know what tags are available and what each of them does.

/ 190