-6

I want to create a string using the unicode values of devnagari script, I want to use this in a php file.

Thanks in advance.

  • did u tried anything? your code? – devpro Nov 10 '16 at 14:58
  • I actually want to use the following code in creating a captcha in devnagari, but i dont think its working as its showing greek characters while its giving the output. – Anand Saran Nov 10 '16 at 14:59
  • $letters = 'भबहगदजडपरकतटचमनवलसयघधझढञफऱखथछठशषणज्ञत्रक्षश्र23456789'; $len = mb_strlen($letters); for ($i = 0; $i< 6;$i++) { $letter = $letters[rand(0, $len-1)]; imagestring($image,9 , 5+($i*30), 20, $letter, $text_color); $word.=$letter; } – Anand Saran Nov 10 '16 at 14:59
  • Possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – ChristianF Nov 10 '16 at 15:05
  • @AnandSaran Code goes in your question, not comments. Edit your question. – Mike Nov 10 '16 at 15:07
  • Please [edit] your question to show [what you have tried so far](http://whathaveyoutried.com). You should include a [mcve] of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Nov 10 '16 at 15:38

1 Answers1

0

You can't safely select a single utf-8 character with $letters[rand(0, $len-1)];, since it's a multi-byte encoding: you just get a single byte. You should use mb_substr instead.

$letter = mb_substr($letters, rand(0, $len-1), 1);
Federkun
  • 36,084
  • 8
  • 78
  • 90