You are here: Re: Ignoring Case « All PHP « IT news, forums, messages
Re: Ignoring Case

Posted by Rik on 10/10/54 11:51

Mike wrote:
> I have set up a simple search in PHP. The user enters some text and
> this is then searched for in a MySQL database. If the text is found
> within the database, the whole text is displayed, highlighting what
> the user entered in red....

> All this works great except if the textfield contains for example
> 'School' and the user searches on 'school' it won't find it.

Aren't you finding them in the database either?
Look at FullText Search:
http://www.phpfreaks.com/tutorials/129/0.php
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

Case-insensitive by default, and highly versatile

> $searchres = str_replace("$_POST[textsearch]","<font
> color=#FF0000><strong>$_POST[textsearch]</strong><font
> color=#000000>",$searchres);

Don't use <font>, it's deprecated.
Use <span> with css, or better, create a class "highlight".

Like Janwillem sais:
str_ireplace() with PHP >= 5 offcourse.
Regex in PHP < 5:
$string = preg_replace('/('.preg_quote($search).')/i','<span
class="highlight">$1</span>',$string);

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация