eval.in

Paste #53702

PHP — PHP 5.5.1, pasted 6 months ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php
/**
 * is PHP str_word_count() multibyte safe?
 * @link http://stackoverflow.com/q/8290537/367456
 */

echo 'New Locale: ', setlocale(LC_ALL, 'en_US.utf8'), "\n\n";

$test   = "aword\xA0bword aword";
$result = str_word_count($test, 2);

var_dump($result);

Program Output

New Locale: en_US.utf8

array(3) {
  [0]=>
  string(5) "aword"
  [6]=>
  string(5) "bword"
  [12]=>
  string(5) "aword"
}

OK (0.012 sec real, 0.013 sec wall, 15 MB, 108 syscalls)

Fork