0

I use preg_match I can't find why the input text will become gibberish? how to solve it?

$input come from loadHTML I'm not sure is it related this problem

$input = $div->nodeValue;
print_r($input);

if (preg_match('/([\$€£])/', $input, $matches)) {
   print_r($matches);
}

£25.00
Array
(
    [0] => �25.00
    [1] => �
    [2] => 25.00
)
raina77ow
  • 103,633
  • 15
  • 192
  • 229
user1775888
  • 3,147
  • 13
  • 45
  • 65

1 Answers1

1

Look at this discussion : preg_match and UTF-8 in PHP

Natively, preg_match() doesn't support Unicode string. You have to add the u modifier to your regular expression to tell the pcre engine to consider both the expression and the subject string as Unicode strings.

$input = '£25.00';
$matches = array();

if (preg_match('/([\$€£])/u', $input, $matches)) {
    print_r($matches); 
}

Prints :

Array
(
    [0] => £
    [1] => £
)
Community
  • 1
  • 1
Benjamin C.
  • 1,076
  • 12
  • 20