PHP doesn't care about string encoding at all; strings are binary data in PHP. Thus, you should know the encoding of the data inside the string if you need the encoding. The question is, does coding do in your case?
If you set the contents of string variables to something like:
$string="ぁ";
It will not contain UTF-8. Instead, it contains a binary sequence that is not a valid UTF-8 character. Therefore, the browser or editor displays a question mark or similar. So, before you start, you already see that something may not be as intended. (It turned out that it was the missing font at my end)
It also shows that your editor file supports UTF-8 or some other Unicode encoding method. Just remember the following: one file - one encoding. If you store a string inside a file, it is encoded in that file. Check your editor, in what encoding you save the file. Then you know the encoding of the string.
Suppose this is really valid UTF-8 (support for my font):
$string="ä";
Then you can do a binary string comparison later:
if ( 'ä' === $string )
Since it is binary in the same file and PHP lines, this works with every encoding. Therefore, usually you do not need to re-encode (change the encoding) data if you use functions that are binary - this means that the data encoding does not change.
For regular expressions, the coding role plays a role. That's why there is a u modifier that signals that you want to make the expression work with Unicode-encoded data. However, if the data is already encoded in Unicode, you do not need to change it to Unicode before using preg_match . However, with your code example, regular expressions are not needed at all, and a simple string comparison does the job.
Summary:
$string="ä"; if ( 'ä' === $string )