-3

I need a script to highlight occurrences of one or more keywords in a text. I have a script in French and I want my script to look for occurrences with special characters and uppercase letters.

My URL is (example): .../?q=être

And I wish the keywords "être", "Être", "etre" and "Etre" to be highlighted.

Is it possible ? (with <mark>...</mark>)

Example :

Bonjour ceci est un texte avec le verbe <mark>être</mark>, avec la majuscule ça aurait
été <mark>Être</mark>, et sans accent <mark>etre</mark>, puis <mark>Etre</mark>.

So:

  • Ignore specials characters
  • Ignore uppercase
Casimir et Hippolyte
  • 83,228
  • 5
  • 85
  • 113
Vivien
  • 1
  • 2
  • Your description and examples don't match up. `Ignore specials characters - Ignore uppercase`...`I wish the keywords "être", "Être", "etre" and "Etre" to be highlighted`. Those have special characters and uppercase letters. You also should provide an example of what you've tried. – chris85 Apr 21 '17 at 20:43
  • Yep, i want to on my URL i have "être", "Être", "etre" and "Etre", and i want to on my string target, the word(s) "être", "Être", "etre" and "Etre" to be highlight. So i want to ignore specials chars and uppercase on all request :) – Vivien Apr 21 '17 at 20:46
  • `ê` is a special character, `Ê` is special and uppercase... or do you mean any form of `etre`? – chris85 Apr 21 '17 at 20:53
  • And if the search word is `"etre"` *(without accent)*, do you want also words with accent to be highlighted? – Casimir et Hippolyte Apr 21 '17 at 20:58
  • @CasimiretHippolyte Looks like it should be a dup of http://stackoverflow.com/questions/14114411/remove-all-special-characters-from-a-string. – chris85 Apr 21 '17 at 21:15
  • @chris85: I don't think, the goal isn't to sanitize the string but to find (and highlight) a word with or without accent, and this without to change the accents of the original string. – Casimir et Hippolyte Apr 21 '17 at 21:18

2 Answers2

-1

This sample will match with the required words in your sentence:

And I wish the keywords "être", "Être", "etre" and "Etre" to be highlighted.

/[êÊeE]tre/
Peter
  • 755
  • 6
  • 19
-1

I, i think :

$utf8 = array(
        '/[áàâãªä]/u'   =>   'a',
        '/[ÁÀÂÃÄ]/u'    =>   'A',
        '/[ÍÌÎÏ]/u'     =>   'I',
        '/[íìîï]/u'     =>   'i',
        '/[éèêë]/u'     =>   'e',
        '/[ÉÈÊË]/u'     =>   'E',
        '/[óòôõºö]/u'   =>   'o',
        '/[ÓÒÔÕÖ]/u'    =>   'O',
        '/[úùûü]/u'     =>   'u',
        '/[ÚÙÛÜ]/u'     =>   'U',
        '/ç/'           =>   'c',
        '/Ç/'           =>   'C',
        '/ñ/'           =>   'n',
        '/Ñ/'           =>   'N',
        '/–/'           =>   '-', // UTF-8 hyphen to "normal" hyphen
        '/[’‘‹›‚]/u'    =>   ' ', // Literally a single quote
        '/[“”«»„]/u'    =>   ' ', // Double quote
        '/ /'           =>   ' ', // nonbreaking space (equiv. to 0x160)
    );

Thx :)

I have found that here : Remove all special characters from a string

Community
  • 1
  • 1
Vivien
  • 1
  • 2
  • Instead of writing and accepting whatever, you should take the time to find a real solution. Keep in mind that your question and the accepted answer have for vocation to help eventual future users. – Casimir et Hippolyte Apr 21 '17 at 21:22