<?php
function wordCountU(string $text): int {
preg_match_all('/[\p{L}\p{N}]+/u', $text, $matches);
return count($matches[0]);
}
echo wordCountU("Hello world"); // 2
echo wordCountU("café au lait, s'il vous plaît"); // 6
echo wordCountU("日本語のテスト 123"); // 3 (depending on tokenizer)
Create a free account and build your private vault. Share publicly whenever you want.