Solved

Character endoding after reading from db

Posted on 2009-03-30
3
267 Views
Last Modified: 2013-11-19
the snippet bellow, it retrieves some data from the db and renders it, it works find except that the rendered text in line echo "$um[jr_comment]"; is displayed like ??? ?????? ????? (question marks) when the letters are non-latin (they are Arabic letters) , is there a way to avoid that?

the rest of the page is displaying correctly because it is done thru joomla, that portion is the only non-standard part of the page that reads directly from the db.
$ans=mysql_query("SELECT * FROM `jr_review_fields`WHERE reviewid in (	$alist)");

	//$um=mysql_num_rows($ans);

	//if($um!='0')

	while($um=mysql_fetch_array($ans)) 

		{

		$us=mysql_query("SELECT username FROM `jr_comments`WHERE `id` = '$um[revid]'");

		while($av=mysql_fetch_array($us))

			{

			echo '<b>'.$av[username].':</b>';

			echo "$um[jr_comment]";

			echo "<br>";

		}

		}

Open in new window

0
Comment
Question by:TheSilverBullet
3 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 24017138
try execute this statement before your Select SQL statement:

$result = mysql_query('SET NAMES utf8;');

//...

$ans=mysql_query("SELECT * FROM `jr_review_fields`WHERE reviewid in (   $alist)");

//...


you may also change the meta setting to be like this:

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


hope this helps

0
 
LVL 3

Expert Comment

by:dr_lionheart
ID: 24017373
try to put this code at the begining of this php file
header("Content-type: text/html; charset=windows-1256");

Open in new window

0
 

Author Closing Comment

by:TheSilverBullet
ID: 31564219
Bravo!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now