Unicode character in PHP string

You can use Unicode characters in a PHP string by including the character directly in the string, or by using the \u escape sequence followed by the Unicode code point of the character in hexadecimal.

Here is an example of using a Unicode character directly in a string:

$str = 'I ❤️ Unicode';

Here is an example of using the \u escape sequence to include a Unicode character in a string:

<?php

$str = "\u{1F497}";  // This is the Unicode code point for the "Growing Heart" emoji

echo $str;

Watch a course Learn object oriented PHP

Note that you may need to set the encoding of your script to UTF-8 in order to use Unicode characters in your PHP strings. This can be done by including the following line at the top of your PHP script:

header('Content-Type: text/html; charset=utf-8');

You can also use the html_entity_decode function to convert HTML entities (such as &#x1F497;) to Unicode characters in a PHP string.