Search code examples
phpwoocommerceunicodestrpos

Why does php strpos() sometimes does not work on Unicode character?


I'm building a system that categorizes woo-commerce products by their name, my product's name is in Hebrew. I have to check in my code if a name of a product contains a Hebrew word.

if I write something like:

strpos(hebrev("סט של בגדים"),hebrev("סט"))

it will work properly but when I try to do it with a return from a function like here

strpos(hebrev($product->get_name()),hebrev("סט"))

it does not work it just returns null. assigning the output of the function to a variable does not seem to work.

I tried it with and without hebrev() and it still does not work.

Am I doing anything wrong? is there any way to fix the problem?


Solution

  • Use:

    $foo = hebrev($product->get_name()); 
    $bar = hebrev("סט"); 
    strpos($foo,$bar);