Decode UTF-8 in HTML Using PHP and SQL?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Darkicon

Thread Starter
Joined
Feb 12, 2008
Messages
265
I'm using a PHP file to query information from an SQL database. The problem is, some names are encoded in UTF-8 and I don't know how to get them to decode and display properly in an HTML page.

Code:
<?php

   $mysqli = new mysqli ('Database_host','Username','Password','eggroup_rank');

   $query = "SELECT * FROM css_rank";
   if( $result = $mysqli->query($query) ) {
      echo "<h1><center>eG Reverse GunGame Stats</center></h1>";
      echo "<h2><center><i>24.161.49.47:27015</i></center></h2>";
      echo "<table border='1''>";
      echo "<tr> <th>ID</th> <th>Name</th> <th>Kills</th> <th>Deaths</th> <th>KDR</th> <th>Headshots</th> <th>Headshot %</th> <th>Suicides</th> <th>Time Played</th> <th>Steam ID</th> </tr>";
      while( $row = $result->fetch_object() ) {
            if($row->deaths == 0 and $row->kills == 0){
				$kdr = 0;}
			elseif($row->deaths == 0){
				$kdr = 1;}
			else{
				$kdr = $row->kills / $row->deaths;
			}
            if($row->kills == 0){
				$headshotperc = 0;}
			else{
				$headshotperc = $row->headshots / $row->kills * 100;
			}			
				$playedtime = $row->played_time / 60;
				echo "<tr><td>";
				echo $row->rank_id;
				echo "</td><td>";
				echo utf8_decode($row->nick);
				echo "</td><td>";
				echo $row->kills;
				echo "</td><td>";
				echo $row->deaths;
				echo "</td><td>";
				echo round($kdr,2);
				echo "</td><td>";
				echo $row->headshots;
				echo "</td><td>";
				echo round($headshotperc,2);
				echo "</td><td>";
				echo $row->sucsides;
				echo "</td><td>";
				echo round($playedtime,2);
				echo "</td><td>";
				echo $row->steamId;
				echo "</td></tr>";
				$kdr = 0;
				$headshotperc = 0;
				$playedtime = 0;
	  }
      echo "</table>";
   } else {
      echo $mysqli->error;
   }

?>
That displays this: http://www.weareepic.com/rank.php

See how some names aren't fully decoding. How can I get them to decode fully?
 

IMM

Joined
Feb 1, 2002
Messages
3,257
It's hard to answer that sort of thing w/o knowing the versions of php and SQL (MySQLi ?).
You might have a look at this one
http://htmlpurifier.org/docs/enduser-utf8.html
particularly the section called Configuring your database and the comments on the ALTER command (if your version is late enough)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top