DrOsama
DrOsama

Reputation: 29

Encoding arabic using UTF8

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

Upvotes: 1

Views: 30745

Answers (6)

KAD
KAD

Reputation: 11122

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

Upvotes: 1

Basheer Hallak
Basheer Hallak

Reputation: 1

  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

Upvotes: 0

Vin
Vin

Reputation: 2165

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

Upvotes: 2

John Youssef
John Youssef

Reputation: 13

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

Upvotes: 0

khaled.alshamaa
khaled.alshamaa

Reputation: 139

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

Upvotes: 3

raj112
raj112

Reputation: 38

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>

Upvotes: 0

Related Questions