php

Working with Persian/Farsi on a Website HTML / PHP / MYSQL

It took me a few hours to figure this out. Though it turned out to be quite simple. Everything needs to be in UTF-8.

HTML

Use the charset meta tag below:

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

MYSQL

The field needs to be collated “utf_8_persian_ci”.

PHP

Set the charset

At the top of the document specify:
header(“Content-type: text/html; charset=utf-8”);

Set the database

Just after opening the database connection specify utf-8 with the following command:
mysql_set_charset(‘utf8’);

FARSI FONTS

Optionally, these open-source fonts can be uploaded and used with @fontface in the stylesheet.

http://www.farsiweb.ir/wiki/Persian_fonts

One Comment

  • Mostafa

    Hello please note that mysqli_set_charset(); requires two parameters first for connection second for charset :

    mysqlli_set_charset($conn, “utf8”);

    and now question marks are gone. worked fine…

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.