0

if i use this it woks just fine:

$string = 'prueba Numero de Documento: 0206728108 Gracias';

preg_match('#Numero de Documento: (\w+)#', $string, $match);
echo $match[1];

OUTPUTS: 0206728108

and this does not work:

$string = 'prueba Número de Documento: 0206728108 Gracias';

preg_match('#Número de Documento: (\w+)#', $string, $match);
echo $match[1];

EMPTY OUTPUT

Ered
  • 465
  • 1
  • 6
  • 23
  • not for me...can you please explain why when i use this it works: `$string = mb_convert_encoding(html_entity_decode($string), "UTF-8","ISO-8859-1");` – Ered Mar 27 '14 at 00:05
  • 2
    Maybe because in var/string you got (probably value from form?) you have something like this: $string = 'prueba Número de Documento: 0206728108 Gracias';, and in php code: preg_match('#Número de Documento: (\w+)#', $string, $match)?http://writecodeonline.com/php/ test code online, and check how spec. chars are converted... – sinisake Mar 27 '14 at 00:11
  • 1
    I don't think that `html_entity_decode` would matter there. See if adding the `u` switch helps. Reference: http://stackoverflow.com/questions/11649019/preg-match-with-international-characters-and-accents – faintsignal Mar 27 '14 at 00:13

1 Answers1

0

Use the u modifier for unicode:

preg_match('#Número de Documento: (\w+)#u', $string, $match);
//                              here ___^
Toto
  • 89,455
  • 62
  • 89
  • 125