2

I'm wanting to use the similar_text() function provided by PHP for Japanese characters. But unfortunately it is giving the wrong answer. How can I make it work?

For Example: similar_text('土橋勇樹', '東日刷株式') gives the output 3, but we can clearly see it should be 0

1
  • This calculates the similarity between two strings as described in Programming Classics: Implementing the World's Best Algorithms by Oliver (ISBN 0-131-00413-1). Note that this implementation does not use a stack as in Oliver's pseudo code, but recursive calls which may or may not speed up the whole process. Note also that the complexity of this algorithm is O(N**3) where N is the length of the longest string. Swapping the first and second may yield a different result; see the example below. php.net/manual/en/function.similar-text.php Jan 22, 2019 at 7:06

1 Answer 1

3

You will want to handle the possible multibytes that are forming the Kanji characters. I am not 100% confident but I suspect similar_text does not support mb and you need a similar solution that can.

This links show peoples attempts at handling mb char similar to the php function.

https://gist.github.com/soderlind/74a06f9408306cfc5de9

https://github.com/antalaron/mb-similar-text

I have not personally tested this but the approach could be right or inspire you to write a custom function.

Also covered in this other post:

how to use similar text php code in arabic

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.