PHP Tutorials - Herong's Tutorial Examples - v5.17, by Herong Yang
French Characters in String Literals - UTF-8 Encoding
This section provides a tutorial example on how enter and use French characters PHP string literals using Unicode UTF-8 encoding. The PHP script file should be stored in UTF-8 format.
First, let's play to some French characters in UTF-8 encoding first.
1. On a Windows system, run Start > All Programs > Accessories > Notepad.
2. In Notepad, enter the following PHP script:
<?php # HelpUtf8French.php #- Copyright 2009 (c) HerongYang.com. All Rights Reserved. # print('<html>'); print('<meta http-equiv="Content-Type"'. ' content="text/html; charset=utf-8"/>'); print('<body>'); print('<b>Help</b><br/>'); print('English: System load is very high.<br/>'); print('French: L\'utilisation de système est très haute.<br/>'); print('</body>'); print('</html>'); ?>
3. To enter the French character, "e with grave", you can run Start > All Programs > System Tools > Character Map. Select "e with grave" on the character map. Click the Select button, then the Copy button. Go back to your Notepad and click Ctrl-V to paste "e with grave" into your PHP script.
4. Select menu File > Save as. Enter the file name as HelpUtf8French.php. Select "UTF-8" in the Encoding field and click the Save button.
5. Copy HelpUtf8French.php to c:\apache\htdocs. Make sure your Internet Information Service is running the local default Web site.
6. Now run Internet Explorer (IE) with http://localhost/HelpUtf8French.php. Your should see the French characters displayed correctly as shown below:
Help English: System load is very high. French: L'utilisation de système est très haute.
7. On the IE window, select menu View > Encoding. You should see UTF-8 is selected.
Another interesting thing you should know is about how Notepad stores a UTF-8 file. When you use UTF-8 encoding to store a file in Notepad, it will insert a UTF-8 marker (3 bytes) at the beginning of the file. Use the "type" command in a command window, you will see this:
>type HelpUtf8French.php <?php # HelpUtf8French.php #- Copyright 2009 (c) HerongYang.com. All Rights Reserved. # print('<html>'); print('<meta http-equiv="Content-Type"'. ' content="text/html; charset=utf-8"/>'); print('<body>'); print('<b>Help</b><br/>'); print('English: System load is very high.<br/>'); print('French: L\'utilisation de système est très haute.<br/>'); print('</body>'); print('</html>'); ?>
The hex value of the UTF-8 marker is 0xEFBBBF. Web server will send it the client. IE browser will not show it on the page, but it will use it to detect the encoding schema, if needed. Not sure on how other browsers will behave this marker.
Table of Contents
Introduction and Installation of PHP
PHP Data Types and Data Literals
Variables, References, and Constants
Expressions, Operations and Type Conversions
Conditional Statements - "if" and "switch"
Loop Statements - "while", "for", and "do ... while"
Function Declaration, Arguments, and Return Values
Interface with Operating System
Introduction of Class and Object
Integrating PHP with Apache Web Server
Retrieving Information from HTTP Requests
Creating and Managing Sessions in PHP Scripts
Sending and Receiving Cookies in PHP Scripts
Controlling HTTP Response Header Lines in PHP Scripts
MySQL Server Connection and Access Functions
Functions to Manage Directories, Files and Images
SOAP Extension Function and Calling Web Services
SOAP Server Functions and Examples
Localization Overview of Web Applications
Using Non-ASCII Characters in HTML Documents
►Using Non-ASCII Characters as PHP Script String Literals
Basic Rules of Using Non-ASCII Characters in HTML Documents
►French Characters in String Literals - UTF-8 Encoding
French Characters in HTML Documents - ISO-8859-1 Encoding
Chinese Characters in String Literals - UTF-8 Encoding
Chinese Characters in String Literals - GB2312 Encoding
Characters of Multiple Languages in String Literals
Receiving Non-ASCII Characters from Input Forms
"mbstring" Extension and Non-ASCII Encoding Management
Managing Non-ASCII Character Strings with MySQL Servers
Parsing and Managing HTML Documents
Configuring and Sending Out Emails
Managing PHP Engine and Modules on macOS