At 9:36 AM +0200 7/12/08, Giulio Mastrosanti wrote:
Hi,
I have a php page that asks user for a key ( or
a list of keys ) and then shows a list of items
matching the query.
every item in the list shows its data, and the
list of keys it has ( a list of comma-separated
words )
I would like to higlight, in the list of keys shown for every item,
the words matching the query,
this can be easily achieved with a search and
replace, for every search word, i search it in
the key list and replace it adding a style tag
to higlight it such as for example to have it in
red color:
if ( @stripos($keylist,$keysearch!== false ) {
$keylist = str_ireplace($keysearch,'<span
style="color:
#FF0000">'.$keysearch.'</span>',$keylist);
}
but i have some problem with accented characters:
i have mysql with character encoding utf8, and
all the php pages are declared as utf8
mysql in configured to perform queries in a case and accent insensitive way.
this mean that if you search for the word
'cafe', you have returned rows that contains in
the keyword list 'cafe', but also 'café' with
the accent. ( I think it has to do with
'collation' settings, but I'm not investigating
at the moment because it is OK for me the way it
works ).
now my problem is to find a way ( I imagine with
some kind of regular expression ) to achieve in
php a search and replace accent-insensitive, so
that i can find the word 'cafe' in a string also
if it is 'café', or 'CAFÉ', or 'CAFE', and
vice-versa.
hope the problem is clear and well-explained in english,
thank you for any tip,
Giulio
Giulio:
Three things:
1. Your English is fine.
2. Try using mb_ereg_replace()
http://www.php.net/mb_ereg_replace
Place the accents you want to change in that and
change them to whatever you want.
3. Change:
<span style="color: #FF0000">'.$keysearch.'</span>'
to
<span class="keysearch">'.$keysearch.'</span>'
and add
.keysearch
{
color: #FF0000;
}
to your css.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php