The ability to access the entire Unicode character set opens up many new possibilities for rendering complex characters, especially characters in alphabets other than Latin-1.
U+202E Unicode character for right-to-left override. The following line of code prints txet desreveR:echo "\u{202E}Reversed text";
echo "\u{202D}"; // returns output to left-to-rightñ (the letter n with a tilde ~ floating above). This is used in words such as mañana (the Spanish word for morning or tomorrow, depending on the context). There is a composed character available, represented by Unicode code U+00F1. Here is an example of its use, which echoes mañana:echo "ma\u{00F1}ana"; // shows mañanaman in an attempt to search for mañana, they will be unsuccessful.n along with the Unicode combining code, which places a floating tilde on top of the letter. In this echo command, the output is the same as previously. Only the way the word is formed differs:echo "man\u{0303}ana"; // also shows mañanaélève (student). You could render it using composed characters, or by using combining codes to float the accents above the letter. Consider the two following examples. Both examples produce the same output, but are rendered differently:echo "\u{00E9}l\u{00E8}ve";
echo "e\u{0301}le\u{0300}ve";Create a file called chap_08_control_and_combining_unicode.php. Be sure to include the meta tag that signals the browser that UTF-8 character encoding is being used:
<!DOCTYPE html>
<html>
<head>
<title>PHP 7 Cookbook</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>Next, set up basic PHP and HTML to display the examples discussed previously:
<body>
<pre>
<?php
echo "\u{202E}Reversed text"; // reversed
//echo "\u{202D}"; // stops reverse
echo "mañana"; // using pre-composed characters
echo "ma\u{00F1}ana"; // pre-composed character
echo "man\u{0303}ana"; // "n" with combining ~ character (U+0303)
echo "élève";
echo "\u{00E9}l\u{00E8}ve"; // pre-composed characters
echo "e\u{0301}le\u{0300}ve"; // e + combining characters
?>
</pre>
</body>
</html>Here is the output from a browser:
