?
Solved

Character endoding after reading from db

Posted on 2009-03-30
3
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…
Suggested Courses

765 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