Highliting / making bold in search results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ssddgreg
Forum Newbie
Posts: 3
Joined: Thu Dec 09, 2004 6:48 am
Location: Slovenia

Highliting / making bold in search results

Post by ssddgreg »

Hi,

I am having problems with my search engine and the function str_ireplace.

I read almost all documentation online possible, but it makes me really angry, because it does not work for my search engine.

I would like to make my keyword bold or highlighting it in the search results (you can try it online at http://www.geoinfo.us/ipa)

For example ... searching for keyword "ap" ,,, it should mark the following chunks of the words

application
applicant
apropriate
mapping
map
tape
tapping


etc.


Here is my code:


Code: Select all

// Search Output

$query = "SELECT * FROM $table WHERE word LIKE '%$word%'";
$result = mysql_query($query);
$nombre = mysql_numrows($result);
if ( $nombre == 0 ) {
echo "<font SIZE=$tablefontsize face=$tablefontface>";
echo $search_no_result;
echo "<BR>";
echo $search_specify;
echo "</font>";
&#125;else&#123;
echo $table_in;
...

Code: Select all

echo "</td> $row_out \n";


while ($row < $nombre )&#123;

$word = mysql_result($result,$row,"word");
$definition 	= mysql_result($result,$row,"definition");
$sampa = mysql_result($result,$row,"sampa");
if ($picsupport == "1") &#123;$picurl 	= mysql_result($result,$row,"picurl");&#125;

// Fill the table with data from the query

echo $row_in ;

echo "<td width='30%' valign=top bgcolor='#ECECEC'><font size=$tablefontsize face=$tablefontface>";
echo "$word";
echo "</font></td>\n";
echo "<td width='30%' bgcolor='#FFF5CE' valign=top><font size=$tablefontsize face=$tablefontface>";
echo "$definition";
echo "</font></td>";
echo "<td width='30%' bgcolor='#E2E8EE' valign=top><font size=$tablefontsize face=$tablefontface>";
echo "$sampa";
echo "</font></td>";
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

Where do you use str_ireplace?
ssddgreg
Forum Newbie
Posts: 3
Joined: Thu Dec 09, 2004 6:48 am
Location: Slovenia

Post by ssddgreg »

Thank you for your reply!

I would like to replace the searching keyword $word with $word. Nothing else.

I do not know how to add the code (see bellow) to my script - it was suggested by a PHP user

Code: Select all

str_ireplace($word,'<em>'.$word.'</em>',$definition);
Please help.

Dejan
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

$definition = str_ireplace($word,'<em>'.$word.'</em>',$definition);

before you echo it
ssddgreg
Forum Newbie
Posts: 3
Joined: Thu Dec 09, 2004 6:48 am
Location: Slovenia

Post by ssddgreg »

Thank you for your reply - but still I am worried.

$definition is just one of 4 columns of results that fill the table with the search result

it fills the following columns in the table:

$word
$definition
$sampa
$pic (here is imagery)

The str_ireplace is interesting in my case only for reults in the column $word, so ther should the replacements be done.

Is this possible to make? I will try the code you sent me.

Thanks for your help and I look forward to hearing from you.

Cheers,

Dejan
Post Reply