Solved

Character endoding after reading from db

Posted on 2009-03-30
3
271 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 51

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.htaccess css/images no longer loading 4 38
Word, Excel, Access icons 4 17
Set time on Session (ASP) 14 23
I'm a Human captcha checkbox 13 21
This article discusses four methods for overlaying images in a container on a web page
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

860 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