R
E
S
O
U
R
C
E
S
       Question Index      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: side or top popup menus, buttons, image rotators, navbars, tons more.
_______________________

Send us your questions and wittiest comments.
_______________________

Report errors on our site.
_______________________

Share your neatest DHTML examples with us; we may publish them.
_______________________


_______________________

      QUESTION INDEX      

Question Index
Browser Insanity
JavaScript
Animation
Buttons and Menus
CSS and HTML
PHP
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS

 INFORMATIVE ARTICLES 

Menus-and-Buttons-
Part-I.htm


Menus-and-Buttons-
Part-II.htm


Change-Div-Size-Color-
and-Location-with-the-
W3C-DOM.htm


Bouncing-Ball-Animation-
with-the-W3C-DOM.htm


Style-Changes-with-the-
W3C-DOM.htm


Animation-with-the-
W3C-DOM.htm


Window-Play-and-Some-
Important-DOM-Methods.htm


Using-getElementsByTagName
-and-getElementsByName.htm


The-CSS-Resources-Intro-
Page.htm


Convert-Word-Files-to-HTML-
and-Install-Editor2-to-
Use-Instead-of-NotePad.htm


CSS-Issues.htm

What Are Fifteen Simple Methods of Doing Web-Page Pop-ups?

Security levels from Javascript and PHP input filtering

What is a regular expression general input validator?

What is a regular expression user name validator?

What is a regular expression password validator?

What is a regular expression email validator?

What is a regular expression URL validator?

How can I convert a Javascript array to a PHP array?

How can I Dynamically Create Input Boxes with Validation?

How do I use JavaScript Object Notation (JSON) in PHP and JavaScript to convert strings and arrays from PHP to JavaScript?

How do I add html to a web page with JavaScript, PHP or ssi includes?

How do I add html to a web page with JavaScript includes?


PHP

How do you put PHP variables in URL and link text?

What is PHP Code for Multiple PSB Hosts?

What is Registration PHP Code for Multiple PSB Hosts?

What is Registration PHP Code for Multiple PSB Hosts with a captcha?

What is Administrator PHP Code for Multiple PSB Hosts?

What's the PHP code for a script for a PSB?

What's the PHP code for a script for PSB updating?

What's the PHP code for a script if you forgot your user name?

What's the PHP code for a script if you forgot your password?

What's the PHP code for a script to change a member's email address?

What's the PHP code for a script to connect to a MySQL database?

What's the PHP code for a script to close a member's account?

What's the PHP code for a script to edit group member?

What's the PHP code for a script to add group member?

What's the PHP code for a script to reset a MySQL table's data to its original?

What's the PHP code for a script to edit a MySQL table's data?

What's the PHP code for a script to change a username?

What's the PHP code for a script to change a password?

What's the PHP code for a script to delete group member?

What's the PHP code for a script to view membership data?

What's the PHP code for a script to change an administrator's password?

What's the PHP code for a script to logout?

What's the PHP code for a script to login?

Security levels from Javascript and PHP input filtering

Security levels and PHP

How can I convert a Javascript array to a PHP array?

What is PHP Code to Prevent Duplicate Data Input - Like User Names or Members?

What is PHP Code for PSB Status Update for Multiple PSB Hosts?

How do I sort 1 PHP array and have the other arrays sort in parallel to how the first array sorts?

How do I use JavaScript Object Notation (JSON) in PHP and JavaScript to convert strings and arrays from PHP to JavaScript?

How do you do PHP-to-JavaScript String Conversion with No JSON?

How do you Convert PHP String to JavaScript String?

How do you Post a JavaScript Array to a PHP Array?

How do you send a value to PHP using JavaScript?

Info on unwanted primary field auto-sorting

How can I do instant article font size, font family, and paragraph formatting with radio buttons?

How can I create custom HTML tags that are safer for MySQL databases?

How can I edit text from MySQL databases by using a textarea box?

How can I highlight matched search terms in a MySQL database table search?

How can I search using not only exact phrase matching but also a series of words to match in a MySQL database table search?

What's the code for an Ajax and PHP Based Input Filter?

Ajax and PHP Based Insult Auto-Completer

How can I use PHP and MySQL for Checking Key Codes to Allow Update to a New Software App Version?




Personal Status Boards (PSB™)

Standard Free PSB

PSB Pro Version

Social PSB

Social PSB Plus (with Email)

Business PSB

Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement




Article Content Management System

Content Management System Introduction

Content Management System—Article Navigation

Content Management System—Article Indexing

Content Management System—Article Editing

Content Management System—Article Searching

Content Management System—Article Deleting

Content Management System—Article Writing

Content Management System—Article Reading

What are the terms of use for our Article Content Management System?




Website Directory Content Management System

Website Directory Navigation

Website Directory—Delete Category

Website Directory—Delete URL

Website Directory—Add URL

Website Directory—Add Category

Website Directory—Directory Creating

Website Directory—View by Category (Demo Code)

Website Directory—View by URL (Demo Code)

Website Directory—View by Category (Demo)

Website Directory—View by URL (Demo)

Website Directory—View

Website Directory—View (Demo)




Photo Gallery Content Management System

Code for Photo Gallery Navigation

Code for Photo Gallery—View

Code for Photo Gallery—Create

Code for Photo Gallery—Add Category

Code for Photo Gallery—Delete Category

Code for Photo Gallery—Add Photo

Code for Photo Gallery—Delete Photo

Code for JavaScript Photo Gallery

JavaScript Photo Gallery




Forum Content Management System

Forum: home page

Forum: search

Forum: login

Forum: topic and replies viewing page

Forum: add topic to database

Forum: add reply to database

Forum: edit topic in database

Forum: create topic in database

Forum: delete topic in database

Forum: delete reply in database

Forum: delete user account in members table



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

Content Management Systems—Article Searching

Article Content Management System

Article Searching

Okay, here is the entire article searching PHP script. This script gets you to input search words or phrases or a series of words to search for in the "articles" MySQL table and it displays any titles/articles that have any of the search words or phrases. The articles that have the most matches are displayed first and those with the least matches are displayed last. For your convenience, all matched search words are highlighted.

The script features 2 types of searching. Click the radio button "match exact phrase" to match exact phrases only. Click "search for words" to search for 2 or more terms at once, separated by spaces. With this latter, the entire articles table will be searched for each search term and scores will be kept for each of the articles in the table. The article with the most matches will be shown first, and so on. If there are italics, bold, underscore, pictures, links, email links, videos, or audios in the article, these will be there in the results. But none of these are the result of HTML tags in the article. They're the result of using our simple-to-use, intuitive custom tags, where, for example: (b-) is used instead of <B> and (bb-) is used instead of </B>. So that's article searching in a nutshell, so let's get to the details:

As you can see, below, we start out with the search term input form where you enter terms. There are 2 radio buttons: "match exact phrase" and "search for words." Select one before submitting search terms.

So that we don't hop around in the script and create confusion, let's just start at the top of the PHP script and work downwards. A very cool function is up first: function highlight(). We declare some variables global so we can use them in and out of the function and values will be retained: global $x, $S;. The $x is the article title or contents, and the $S is the search term. In preg_match_all("/$S+/i", $x, $matches); the first item is the string to match, in regular expression form so the + means 1 or more. The second item is the string to search, and the third item is the matches that happen, in an array. If there are matches, we do highlighting, going through the array of matches and running a string replacement function on them. The str_replace() function will replace all occurrences of the search string with the replacement string. So we search $x for the matches and replace the matched strings with the matched strings enclosed in an HTML span tag that styles the search word with a light blue background—much nicer to look at than yellow: $x = str_replace($match, '<span style="background-color:lightblue;">'.$match.'', $x);.

Next we include the configure file contents so the MySQL queries of the database table will work. Then we grab the POSTed search terms and search type. For the latter, there is "match exact phrase" wherein the POSTed value would be "phrase," or "search for words" wherein the POSTed value would be "word." Note that there are warnings if no terms were entered or the entry is under 3 characters long. The only allowable characters in the search terms are alphanumerics or . , ! ? , and tags get thrown out and the string gets escaped with the ever-handy PHP function mysql_real_escape_string(). These security precautions will get relative—but not absolute—safety. For absolute safety you need to be dead—nothing will EVER endanger you again!

Next we declare a $score array and a $N array. The first keeps score of each record's/article's search term matching score. The second keeps the reference number (like an ID) to use for identifying which record/article we're referring to. Next we find the actual values of the reference number field, N, for each record and stuff it gently but lovingly into its $N array. Then we stick a zero into each element in the $score array.

The entire rest of the PHP script is of the form if($t=="words"){DO THIS} else {DO THIS INSTEAD} with the second clause being used if the searcher is going for "phrase" rather than "word."

Next, $gotmatch=0; is the match or no match flag being initialized. And $searchtermarray = explode(" ", $S); is dumping the space-separated search terms into an array—explosively—with the explode() function. And $terms=count($searchtermarray); is counting the terms with the count() function. Next comes the old faithful "for" loop where we need to go through the terms one at a time to search on them. We do not need multi-term $S anymore—just the $searchtermarray[$i] values, so we use $S for each word we look for. The SELECT FROM WHERE LIKE SQL keywords give us a way to search inside title and content for matches. The wild card % on either side of the search term gives us a magical way to look for the term no matter where it is in the record/article/title. Here is the MySQL query: $r=mysql_query("SELECT * FROM articles WHERE title LIKE '%" . $S . "%' OR content LIKE '%" . $S . "%'") or die('Error ,search failed');. If anything in the title or content matches any term, we have a winner and we can go on. Otherwise we display the failure message.

If we succeeded, we put a loop within a loop. We need to search on all terms (first loop) AND we need to search through every single article (second loop). In this second loop, you can see why we needed the $N array: in the "SELECT * FROM articles WHERE N='$N[$k]'" query, the reference numbers in the articles table are not necessarily 1 to n in sequence. What about when a record gets deleted and its reference number N is never heard from again? Notice that we concatenate title and contents together for convenience and then once again use preg_match_all("/$S+/i", $x, $matches); to see if we struck paydirt. If so, we add the number of matches to that record's overall score. Once all terms have been looked for in all records, we use array_multisort($score,SORT_DESC,SORT_NUMERIC,$N); to sort the $score array from highest to lowest and have the $N array sort in parallel to this so the correct record with the high score displays first, and so on. To understand multisort, check out PHP-using-array_multisort.html. Only the first array sorts—any other arrays in a multisort simply rearrange themselves in parallel to the first array (in this case $score).

Now we need a loop to display the records in descending score order and we'll do our highlighting in the process. So we loop through the records with score higher than zero, recalling that the $N[$k] value for $k=1 corresponds to the record with the highest score, and $k=2 will get a $N[$k] value that corresponds to the record with the second highest score, and so on, due to the multisort we just did. Then for each of these we loop through the terms and set $S=$searchtermarray[$i]; and run the highlight() function on both the title and the contents with $x=$tt;highlight();$tt=$x; and $x=$cn;highlight();$cn=$x;. You can see why the $S and $x variables needed to be global. Once we're finished highlighting one record's title and contents, we display the title and then further process the contents:

The indenting script is especially interesting since in writing articles with our system, you're allowed to hit Return/Enter for new paragraphs, and when the PHP script below finds a Return we use the nl2br() function to turn it into <BR />. This nl2br() function processes contents like this: $content=nl2br($content), which turns Returns to break tags: <BR />—as we noted. But let's look at the preg_replace function that turns these tags, in turn, to </p><p> tags: $pattern = '/(<BR\s\/>)+/i' sets up the regular expression replacement pattern for the function, and the i at the end is to make it case insensitive. $replacement = '</p><p>' sets up the replacement text. Finally, the function itself: $content=preg_replace($pattern, $replacement, $content).

Next comes dealing with all the custom tags we invented for various HTML code creation purposes. You can learn about the custom codes for italics, bold, underline, links, email links, pictures, videos, and sounds, if you wish, in order to understand what's going on below. The purpose of these custom tags is to be safer than regular HTML tags.

For italics, the tag we get writers to use is (i-) and (ii-) for start and end tag, which our PHP script turns into <i> and </i>, using '/\(i-\)/i' and '/\(ii-\)/i' as regular expression replacement patterns and '<i>' and '</i>'as replacement text. The same is done for underline and bold. And (p-) and (pp-) are the picture tags, with '<center><br><IMG SRC="' replacing the first and
'" BORDER=0><br><br></center>' replacing the second, and the image name like pic.png in between. A special replacement happens if the writer puts 2 dots in front of the file name: ../ is added to the start of the image source so a picture can be in a higher level folder or no folder (except public_html).

With links, (l-) turns into '<a href="http://', (ll-) turns into "> after the domain, and (lll-) turns into </a> after the link text. With video, (v-) turns into '<div style="width:580px"><br><center><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/', (vv-) turns into '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' after the special letter codes in their video's YouTube embed code, and (vvv-) turns into '&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br><br></center></div>' after they repeat their letter code. Nutty? It works! The special letter codes are simply the ones between   http://www.youtube.com/v/   and   &hl=en_US&fs=1& in their embed code, which YouTube happily shares with video uploading people and visitors alike.

For audio, they need to load a sound.js file into their web page's folder which has only this in it: function sound(s,q) {document.getElementById(q).innerHTML="<embed src='"+s+"' hidden=true autostart=true loop=false>"} to empower the audio. Then (a-) is turned into '<div style="width:580px"><br><center><script src="sound.js"></script><span id="a1"></span><form><input type="button" value="', (aa-) is turned into '" onClick="sound(\'' after the sound's name, and (aaa-) is turned into '\',\'a1\')"></form><br><br></center></div>' after the sound file name such as siren.mp3. Note that the backslashes are all escaping the quotes; also, a button to press to get sound will show up onscreen to give readers of the article something to press to get the sound.

Email links get (e-) turned into '<a href="mailto:', (ee-) turned into '@' after the 1st section of the email before the @ and before the second, (eee-) turned into '?subject=' before the email's subject text, (eeee-) turned into '">' after the email subject, and (eeeee-) turned into '</a>' after the link text.

The exact phrase matching script is below the word matching script and it's much the same except it doesn't need to loop through the search terms, since the inputted search phrase is only one term to search for. It uses scores and the $score array, and it uses the $N array as well. It also uses the multisort() function as well as the highlight() function. But it has no use for the $searchtermarray array. It uses all the same custom tags functions to display italics, bold, underscore, pictures, links, email links, videos, or audios in the articles that it finds the search phrase in.

SAVE THIS PAGE AS: cms-search-articles.php


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Search Articles—Content Management System (CMS)</TITLE>
<meta name="description" content="Search Articles—Content Management System (CMS)">
<meta name="keywords" content="Search Articles,Content Management System,Content Management System Articles,php,CMS,javascript, dhtml, DHTML">
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#ddd}
p, li {font:13px Verdana; color:black;text-align:left;text-indent:2em;margin-bottom:-1em}
td {padding:10px}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
h3 {font:bold 15px Verdana;}
.title {position:absolute;top:10px;left:130px;width:842px}
.textbox {position:absolute;top:190px;left:190px;width:772px;}
.info {position:absolute;top:238px;left:2px;width:160px;background-color:#bbb;border:1px solid blue;padding:5px}
</style>
</head>
<body>

<div class='title'>
<h1>Search Articles—Content Management System (CMS)</h1>

<form method="post" action="cms-search-articles.php">
<table width="700" border="0" cellpadding="2" cellspacing="2" align="center">
<tr>
<td width="130">Search  for:</td>
<td width='570'><input name="search" type="text" size="100"></td>
</tr>
<b>                           Options:      </b>
<input type="radio" name="searchtype" value="phrase" checked> match exact phrase          
<input type="radio" name="searchtype" value="words"> search for words<br>
<tr>
<td> </td><td><input name="retrieve" type="submit" value="Search Articles in DB">
<input name="reset" type="reset" value="Reset"></td>
</tr>
</table>
</form>
</div>

<div class='textbox'>

<?php

function highlight() {
global $x, $S;
if (strlen($x) < 1 || strlen($S) < 1) {return;}
preg_match_all("/$S+/i", $x, $matches);
if (is_array($matches[0]) && count($matches[0]) >= 1) {
foreach ($matches[0] as $match) {
$x = str_replace($match, '<span style="background-color:lightblue;">'.$match.'</span>', $x);
}}}

include_once"config.php";

$S=$_POST['search'];$t=$_POST['searchtype'];

if(!isset($S)){echo '<script language="javascript">alert("Enter search terms.");</script>';
}else{

if (strlen($S)<3) {echo '<script language="javascript">alert("Enter longer search terms.");</script>';
}else{

$S=strip_tags($S);
$pattern2 = '/[^a-zA-Z0-9\\s\\.\\,\\!\\?]/i';
$replacement = '';
$S=preg_replace($pattern2, $replacement, $S);
$S=mysql_real_escape_string($S);

$score=array();$N=array();

$res = mysql_query("SELECT N FROM articles") or die(mysql_error());
while ($row = mysql_fetch_row($res)) {
array_push ($N, $row[0]);
}

$number=mysql_num_rows($res);

for($i=0;$i<$number;$i++) {
$score[$i]=0;
}

if($t=="words"){

$gotmatch=0;
$searchtermarray = explode(" ", $S);
$terms=count($searchtermarray);

for($i=0;$i<$terms;$i++) {
$S=$searchtermarray[$i]; //do not need multi-term $S anymore--just the $searchtermarray[$i] values

$r=mysql_query("SELECT * FROM articles WHERE title LIKE '%" . $S . "%' OR content LIKE '%" . $S . "%'") or die('Error ,search failed');
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;}
}

if ($gotmatch==0){echo '<script language="javascript">alert("The search was unsuccessful.");</script>';$S='';
}else{

for($i=0;$i<$terms;$i++) {
$S=$searchtermarray[$i];

for($k=0;$k<$number;$k++) {
$res = mysql_query("SELECT * FROM articles WHERE N='$N[$k]'") or die(mysql_error());
while($row = mysql_fetch_array($res)){
$x=$row['title']." ".$row['content'];
}
preg_match_all("/$S+/i", $x, $matches); $m=count($matches[0]);
$score[$k]=$score[$k]+$m;
}}

array_multisort($score,SORT_DESC,SORT_NUMERIC,$N);

echo '<table width="772" border="1">';

for($k=0;$k<$number;$k++) {
$res = mysql_query("SELECT * FROM articles WHERE N = '$N[$k]'") or die(mysql_error());
while($row = mysql_fetch_array($res)){
$tt=$row['title'];
$cn=$row['content'];

if($score[$k]>0){

for($i=0;$i<$terms;$i++) {
$S=$searchtermarray[$i];

$S=stripslashes($S); //unescape quotes and backslashes so they're normal

$x=$tt;highlight();$tt=$x; //highlight search terms
$x=$cn;highlight();$cn=$x; //highlight search terms
}

echo '<tr><td><b>';
echo $tt;
echo "</b></td></tr><tr><td>";
$content=$cn;
$content=nl2br($content); //Enter turns into <BR />
$pattern = '/(<BR\s\/>)+/i';
$replacement = '</p><p>'; //turn any <BR />s into a </p><p> to allow indent since <p>s are css styled to indent!
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(i-\)/i';
$replacement = '<i>'; //turn any (i-)s into a <i>s to allow italics
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(ii-\)/i';
$replacement = '</i>'; //turn any (ii-)s into a </i>s to allow italics
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(b-\)/i';
$replacement = '<b>'; //turn any (b-)s into a <b>s to allow bold
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(bb-\)/i';
$replacement = '</b>'; //turn any (bb-)s into a </b>s to allow bold
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(u-\)/i';
$replacement = '<u>'; //turn any (u-)s into a <u>s to allow underline
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(uu-\)/i';
$replacement = '</u>'; //turn any (uu-)s into a </u>s to allow underline
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(p-\)\.\./i';
$replacement = '<center><br><IMG SRC="../'; //turn any (p-)s into start of image tag to allow image
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(p-\)/i';
$replacement = '<center><br><IMG SRC="'; //turn any (p-)s into start of image tag to allow image
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(pp-\)/i';
$replacement = '" BORDER=0><br><br></center>'; //turn any (pp-)s into end of image tag to allow image
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(l-\)/i';
$replacement = '<a href="http://'; //turn any (l-)s into <http:// to allow link protocol
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(ll-\)/i';
$replacement = '">'; //turn any (ll-)s into "> to allow url
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(lll-\)/i';
$replacement = '</a>'; //turn any (lll-)s into </a> to link text
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(v-\)/i';
$replacement = '<div style="width:580px"><br><center><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/'; //turn any (v-)s into start of video tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(vv-\)/i';
$replacement = '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'; //middle of video tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(vvv-\)/i';
$replacement = '&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br><br></center></div>'; //end of video tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(a-\)/i';
$replacement = '<div style="width:580px"><br><center><script src="sound.js"></script><span id="a1"></span><form><input type="button" value="'; //turn any (a-)s into start of audio tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(aa-\)/i';
$replacement = '" onClick="sound(\''; //middle of audio tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(aaa-\)/i';
$replacement = '\',\'a1\')"></form><br><br></center></div>'; //end of audio tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(e-\)/i';
$replacement = '<a href="mailto:'; //turn any (e-)s into <a href="mailto: to allow link protocol
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(ee-\)/i';
$replacement = '@'; //turn any (ee-)s into @ to allow email @ sign
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(eee-\)/i';
$replacement = '?subject='; //turn any (eee-)s into ?subject= to allow email subject
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(eeee-\)/i';
$replacement = '">'; //turn any (eeee-)s into "> to allow email address
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(eeeee-\)/i';
$replacement = '</a>'; //turn any (eeeee-)s into </a> to allow link text
$content=preg_replace($pattern, $replacement, $content);
echo $content;
echo "<br><br></td></tr>";
}}}
echo '</table>';

}

}else{

$gotmatch=0;

$r=mysql_query("SELECT * FROM articles WHERE title LIKE '%" . $S . "%' OR content LIKE '%" . $S . "%'") or die('Error ,search failed');
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;}

if ($gotmatch==0){echo '<script language="javascript">alert("The search was unsuccessful.");</script>';$S='';
}else{

for($k=0;$k<$number;$k++) {
$res = mysql_query("SELECT * FROM articles WHERE N='$N[$k]'") or die(mysql_error());
while($row = mysql_fetch_array($res)){
$x=$row['title']." ".$row['content'];
}
preg_match_all("/$S+/i", $x, $matches); $m=count($matches[0]);
$score[$k]=$score[$k]+$m;
}}

array_multisort($score,SORT_DESC,SORT_NUMERIC,$N);

echo '<table width="772" border="1">';

for($k=0;$k<$number;$k++) {
$res = mysql_query("SELECT * FROM articles WHERE N = '$N[$k]'") or die(mysql_error());
while($row = mysql_fetch_array($res)){
$tt=$row['title'];
$cn=$row['content'];

if($score[$k]>0){

$S=stripslashes($S); //unescape quotes and backslashes so they're normal

$x=$tt;highlight();$tt=$x; //highlight search terms
$x=$cn;highlight();$cn=$x; //highlight search terms

echo '<tr><td><b>';
echo $tt;
echo "</b></td></tr><tr><td>";
$content=$cn;
$content=nl2br($content); //Enter turns into <BR />
$pattern = '/(<BR\s\/>)+/i';
$replacement = '</p><p>'; //turn any <BR />s into a </p><p> to allow indent since <p>s are css styled to indent!
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(i-\)/i';
$replacement = '<i>'; //turn any (i-)s into a <i>s to allow italics
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(ii-\)/i';
$replacement = '</i>'; //turn any (ii-)s into a </i>s to allow italics
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(b-\)/i';
$replacement = '<b>'; //turn any (b-)s into a <b>s to allow bold
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(bb-\)/i';
$replacement = '</b>'; //turn any (bb-)s into a </b>s to allow bold
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(u-\)/i';
$replacement = '<u>'; //turn any (u-)s into a <u>s to allow underline
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(uu-\)/i';
$replacement = '</u>'; //turn any (uu-)s into a </u>s to allow underline
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(p-\)\.\./i';
$replacement = '<center><br><IMG SRC="../'; //turn any (p-)s into start of image tag to allow image
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(p-\)/i';
$replacement = '<center><br><IMG SRC="'; //turn any (p-)s into start of image tag to allow image
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(pp-\)/i';
$replacement = '" BORDER=0><br><br></center>'; //turn any (pp-)s into end of image tag to allow image
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(l-\)/i';
$replacement = '<a href="http://'; //turn any (l-)s into <http:// to allow link protocol
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(ll-\)/i';
$replacement = '">'; //turn any (ll-)s into "> to allow url
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(lll-\)/i';
$replacement = '</a>'; //turn any (lll-)s into </a> to link text
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(v-\)/i';
$replacement = '<div style="width:580px"><br><center><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/'; //turn any (v-)s into start of video tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(vv-\)/i';
$replacement = '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'; //middle of video tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(vvv-\)/i';
$replacement = '&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br><br></center></div>'; //end of video tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(a-\)/i';
$replacement = '<div style="width:580px"><br><center><script src="sound.js"></script><span id="a1"></span><form><input type="button" value="'; //turn any (a-)s into start of audio tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(aa-\)/i';
$replacement = '" onClick="sound(\''; //middle of audio tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(aaa-\)/i';
$replacement = '\',\'a1\')"></form><br><br></center></div>'; //end of audio tag
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(e-\)/i';
$replacement = '<a href="mailto:'; //turn any (e-)s into <a href="mailto: to allow link protocol
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(ee-\)/i';
$replacement = '@'; //turn any (ee-)s into @ to allow email @ sign
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(eee-\)/i';
$replacement = '?subject='; //turn any (eee-)s into ?subject= to allow email subject
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(eeee-\)/i';
$replacement = '">'; //turn any (eeee-)s into "> to allow email address
$content=preg_replace($pattern, $replacement, $content);
$pattern = '/\(eeeee-\)/i';
$replacement = '</a>'; //turn any (eeeee-)s into </a> to allow link text
$content=preg_replace($pattern, $replacement, $content);
echo $content;
echo "<br><br></td></tr>";
}}}
echo '</table>';

}}}

mysql_close();

?>

</div>

<script language="javascript">
/*
var t = <?php echo json_encode($T); ?>;
document.saveit.titles.value=t;
var c = <?php echo json_encode($content); ?>;
if (c != null && c!=""){document.saveit.content.value=c;}
*/
</script>

<div id='info' class='info'>No hyphens (-) or underscores (_) or Enter/Return allowed in search terms. Use letters, numbers, spaces and these: <B> , . ? ! </b> in searches. Click "match exact phrase" to math exact phrases only. Use "search for words" to search for 2 or more terms at once. Relevancy will determine the order of articles returned as search results—whatever article has the most word matches will be displayed first as it's the most relevant to your search.<br></div>

<?php include("navigation.html"); ?>

</body>
</html>