0

I was developing a site for my customer which uses both English and Tamil languages.

I need to find the length of a Tamil string to generate stripped content.

Can anyone suggest me how to find the length of a Tamil string and substr function for Tamil language.

Arulkumar
  • 12,966
  • 14
  • 47
  • 68
user3535945
  • 241
  • 1
  • 10

2 Answers2

4

Use \pL\pM to count Tamil characters length. It will gives exact count of Tamil letters

$word = "மொழிகளும்";
$regex = "/\pL\pM*|./u";//Unicode letter & Unicode Mark
preg_match_all($regex, $word, $out);
echo count($out[0]);
Neechalkaran
  • 413
  • 4
  • 6
2

Better use mb_strlen(). That should take special chars into account. There are multi-byte equivalents of almost all string functions. If this still does not work, try it with the correct encoding.

Powerriegel
  • 595
  • 5
  • 16