PHP-REGEX: accented letters matches non-accented ones, and visceversa. How to achive it?

Posted by Lightworker on Stack Overflow See other posts from Stack Overflow or by Lightworker
Published on 2012-05-31T16:06:13Z Indexed on 2012/05/31 16:40 UTC
Read the original article Hit count: 377

I want to do the typical higlight code.

So I have something like:

$valor = preg_replace("/(".$_REQUEST['txt_search'].")/iu", "<span style='background-color:yellow; font-weight:bold;'>\\1</span>", $valor);

Now, the request word could be something like "josé". And with it, I want "jose" or "JOSÉ" or "José" or ... highlighted too.

With this expression, if I write "josé", it matches "josé" and "JOSÉ" (and all the case variants). It always matches the accented variants only.

If I search "jose", it matches "JOSE", "jose", "Jose"... but not the accented ones.

So I've partially what I want, cause I have case insensitive on accented and non-accented separately.

I need it fully combined, wich means accent (unicode) insensitive, so I can search "jose", and highlight "josé", "josÉ", "José", "JOSE", "JOSÉ", "JoSé", ...

I don't want to do a replace of accents on the word, cause when I print it on screen I need to see the real word as it comes.

Any ideas?

Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about regex