php strstr not detecting substring in a arabic string

php detect file encoding
php detect encoding
php convert special characters to unicode
php convert utf8 to ascii
php substr
php convert string to latin1
display unicode characters in php
php convert string to utf-8

Can anyone please tell me ,How to make string matching function work with Arabic keywords? The Following keywords are detected as Unmatched in php. Though these are matching in normal browser searching.

    if (strstr('الهيئة العامة للقوى العاملة', 'قوى العامله') != false) {
          } else {

Result comes as 'out'.


Try this .. I have PHP Version 5.6.23

$string = 'الهيئة العامة للقوى العاملة';
$find_me = 'قوى العاملة';
if (strstr($string, $find_me) != false) {
          } else {


You can see output here

strlen - Manual, <?php // the Arabic (Hello) string below is: 59 bytes and 32 characters utf8_decode() converts characters that are not in ISO-8859-1 to '?', which, for the purpose of counting, is quite alright. up · down. 24 return substr( $word, 0, $​limit ).""; The input string. If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string,

The result for the match you are doing should be out, so it's working just fine for you. There is no match for the search you are doing since the last letter in the word العاملة is different between the two strings.

strcmp - Manual, echo '$var1 is not equal to $var2 in a case sensitive string comparison'; safe string comparison of the first n characters; strstr() - Find the first occurrence of a with Latin scripts; or final, middle, then isolated, initial with Arabic script), symbols, others. If you don't want to bother finding out why, then this is a simple solution: شرح خاصية استخراج نص من نص بواسطة StrStr StriStr StrChr. [ PHP 5 In Arabic ] #58 - String Function in C Programming | How to Find Substring in String - Learn

Try to re-save the page in

UTF-8 Wihtout Bom

this work for me

mb_detect_encoding - Manual, The detected character encoding or FALSE if the encoding cannot be detected from the given A simple way to detect UTF-8/16/32 of file by its BOM (not work with string or file without BOM) if(!valid_nextbyte(ord(substr($string, $i++, 1)))) mb_strstr() finds the first occurrence of needle in haystack and returns the portion of haystack.If needle is not found, it returns FALSE.

utf8_encode - Manual, This function converts the string data from the ISO-8859-1 encoding to UTF-8. Note: Many web pages This function will not convert such Windows-1252 characters correctly. Use a different Avoiding use of preg_match to detect if utf8_encode is needed: <?php $string $character=ord(substr($line,$i,1)); $​found=0; The substr () function returns a part of a string. PHP 7.0 - If string = start (in characters long), it will return an empty string. Earlier versions returns FALSE. PHP 5.2.2 - 5.2.6 - If start has the position of a negative truncation, FALSE is returned. Other versions get the string from start. Using the start and length parameters with

strpos - Manual, strpos — Find the position of the first occurrence of a substring in a string If needle is not a string, it is converted to an integer and applied as the ordinal value  strrchr() - Find the last occurrence of a character in a string; substr_replace() - Replace text within a portion of a string; preg_match() - Perform a regular expression match; trim() - Strip whitespace (or other characters) from the beginning and end of a string; mb_substr() - Get part of string; wordwrap() - Wraps a string to a given number of characters

[ PHP 5 In Arabic ] #57 - String Functions, Your browser does not currently recognize any of the video formats available. Click here to visit Duration: 7:44 Posted: Sep 20, 2015 This tutorial will help you to check if a string contains any substring in PHP programming language. For example, you want to run a specific line of code only if an input string contains another substring in it.

  • worked fine for me, got back in.
  • Hi @Fred-ii- but i am always getting out. Can you aid me what can be possible reason?
  • what's the file's encoding and the server it's on? I can't replicate the error with any encodings.
  • Thanks for the reply. Encoding is UTF-8.
  • maybe stristr() will work but I can't see how that would make a difference.
  • But following doesn't work. @Mittul It gives out when put in variable. <?php $single_description_data='الهيئة العامة للقوى العاملة'; $single_organization='القوى العاملة'; if (strstr($single_description_data, $single_organization) != false) { echo'in'; } else { echo'out'; }die; ?>
  • @brstdev ok i have updated my answer above with variables. Please check now.