Encoding arabic using UTF8

家住魔仙堡 提交于 2019-12-08 05:28:55

问题


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


回答1:


  // 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">';



回答2:


  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'); ?>



回答3:


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




回答4:


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:


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




回答6:


  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



来源:https://stackoverflow.com/questions/18303255/encoding-arabic-using-utf8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!