1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Decode UTF-8 in HTML Using PHP and SQL?

Discussion in 'Software Development' started by Darkicon, Apr 23, 2010.

Thread Status:
Not open for further replies.
  1. Darkicon

    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?
     
  2. IMM

    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)
     
  3. Darkicon

    Darkicon Thread Starter

    Joined:
    Feb 12, 2008
    Messages:
    265
    PHP Version 5 and MySQL Version 5.0.70.
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/918855

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice