Encoding arabic using UTF8

2019-06-02 05:53发布

Currently I created simple website using include system

  1. header.php - contains first part of HTML page (Head, meta tags, JS codes ... etc )

  2. page.php - contains simple php code

    page content

My main problem with arabic language

I have to put

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

in page.php, footer.php between <head> tags otherwise the arabic will not support correctly.

This prevents page validation because of these tags.

Is there any method to avoid this problem ?

Thanks

6条回答
仙女界的扛把子
2楼-- · 2019-06-02 06:01

Apart from all of the answers... Make sure your (HTML/PHP) files are saved with the right encoding utf-8

查看更多
手持菜刀,她持情操
3楼-- · 2019-06-02 06:03

1- Put this

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

2- You should also save the documents in UTF-8 not ANSI

查看更多
Luminary・发光体
4楼-- · 2019-06-02 06:14

All you need is to put this

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

in a file that you include/include_once in your pages

EDIT. example:

header.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>my title in العربية</title>
  </head>
  <body>

mypage.php

<?php
include_once 'header.html';
?>

<p>
العربية
</p>

<?php 
include 'foot.html';
?>

foot.html

<div>my footer</div>

</body>
</html>
查看更多
何必那么认真
5楼-- · 2019-06-02 06:16
  1. Your headers should appear as the following:

    <!DOCTYPE html>
    <html lang="ar">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
    
  2. Save your document as utf-8

查看更多
小情绪 Triste *
6楼-- · 2019-06-02 06:18
  // Send a raw HTTP header 
  header ('Content-Type: text/html; charset=UTF-8'); 

  // Declare encoding META tag, it causes browser to load the UTF-8 charset 
  // before displaying the page. 
  echo '<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />'; 

  // Right to Left issue 
  echo '<body dir="rtl">';
查看更多
聊天终结者
7楼-- · 2019-06-02 06:25
  1. Encode the arabic string into UTF-8 using a tool like this. (No need to change any settings - that link has the the correct settings you need).

  2. Then use utf8_decode() to decode the string back.

Example:

<?php echo utf8_decode('your_encoded_string_goes_here'); ?>
查看更多
登录 后发表回答