3

I want to replace an exact word using preg_replace by \b modifier as mentioned in this question.

But it seems that won't work for Unicode characters such as Persian and Arabic. This example works:

preg_replace('/(\bto\b|\bis\b)/i', '', 'go to test if var is set using isset')

But this one won't work:

preg_replace('/(\bاز\b|\bبه\b)/i', '', 'راه مدرسه به خونه از اونجا میگذره')

Is there a way to get the required result, splitting on word boundaries?

1 Answer 1

4

Got it myself, have to use \u modifier simply as

preg_replace('/(\bاز\b|\bبه\b)/iu', '', 'راه مدرسه به خونه از اونجا میگذره')

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.