Re: Ignoring Case



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


.



Relevant Pages

  • Web Developers - Happy Hearts And HDTV! - Lockergnome
    ... Certificate on your MSIIS Web server. ... getting data from a database is only half the problem. ... Zend recently started a series about building rock solid code in PHP. ... which provides bulk database conversion. ...
    (freebsd-questions)
  • Re: Techniques for Vulneability discovery
    ... in mind) so i searched the net for some free database driven software and came ... the first thing i did was grab some info about PHP programming and some MySQL ... I did some more reasearch on different types of web based "input validation" ... PHP and SQL docs, etc.. ...
    (Vuln-Dev)
  • Re: Techniques for Vulneability discovery
    ... in mind) so i searched the net for some free database driven software and came ... the first thing i did was grab some info about PHP programming and some MySQL ... I did some more reasearch on different types of web based "input validation" ... PHP and SQL docs, etc.. ...
    (Security-Basics)
  • Re: CSS + xhtml static site - going dynamic?
    ... PHP then fills each content area. ... A better alternative is to have PHP pull the content off a database. ... management - menus and page linking need to be done by hand. ... So the second part is to formally build the linking structure into the ...
    (uk.net.web.authoring)
  • Re: CSS + xhtml static site - going dynamic?
    ... PHP then fills each content area. ... A better alternative is to have PHP pull the content off a database. ... management - menus and page linking need to be done by hand. ... So the second part is to formally build the linking structure into the ...
    (uk.net.web.authoring)