0

i want to filer a persian words in php i want to replace خ with خیابان here my code but it dident work its my code


preg_replace('/\bخ\b/'
,'خیابان'
,'خ جردن-بالاتر از اسفندیار-خ سعیدی-نبش مهرداد');

but my output is zero!!!!

hosein in jast
  • 370
  • 2
  • 15
  • If I run this I get "خ جردن-بالاتر از اسفندیار-خ سعیدی-نبش مهرداد". – KIKO Software Feb 02 '20 at 14:49
  • 1
    Does this answer your question? [Matching Unicode letter characters in PCRE/PHP](https://stackoverflow.com/questions/4983392/matching-unicode-letter-characters-in-pcre-php) – Joffrey Schmitz Feb 02 '20 at 14:54
  • The given code does not output anything, so "zero" looks like a pretty strange result – Nico Haase Feb 02 '20 at 16:45

1 Answers1

1

Basically you should use the unicode modifier in your regex:

<?php
$regex = '/\bخ\b/u';
$repl = 'خیابان';
$text = 'خ جردن-بالاتر از اسفندیار-خ سعیدی-نبش مهرداد';

echo preg_replace($regex, $repl , $text);
dimasdmm
  • 318
  • 4
  • 15