H. Pauwelyn ツ H. Pauwelyn ツ - 1 year ago 118
PHP Question

� or □ instead of é with PHP

Why do browsers output

(for Google Chrome and Firefox) or
(for IE) instead of
? The data comes from a MS SQL database that I access with PHP.

Here is my code:

<?php //on top of php file
header( 'Content-Type: text/html; charset=UTF-8' );
$conn = sqlsrv_connect('.\\SQLEXPRESS', array ("Database" => "FastCycle"));

<!--in head-->
<meta charset="utf-8"/>
<!--Also tried this-->
<meta http-equiv="x-ua-compatible" content="IE=edge;chrome=" />

<!--in body-->
<table border="1" id="table2" class="table2">

$teller = 1;
$query = sqlsrv_query($conn, "select h.ID as hId, h.Naam as hoofdtsuk, c.id as cId, c.Naam as categorie, i.id as iId, i.Naam as item, i.icoon as icoon from CategorieItem i right join Categorie c on i.CategorieID = c.ID right join CategorieHoofdstuk h on c.CategorieHoofstukID = h.ID order by hoofdtsuk, categorie, item");

while ($rij = sqlsrv_fetch_array($query)){

$icoon = "";
$link = "";

if (!isset($rij['icoon']) || trim($rij['icoon']) === '') {
$icoon = '<img src="imgs/geen.jpg"/>';
$link = '<input type="text" placeholder="geef een icoon in" name="item[' . $rij['iId'] . ']"/>';
else {
$icoon = '<img src="imgs/' . $rij["icoon"] . '"/>';

print "<tr><td class='teller'>". $teller++ ."</td><td>". $rij['hId'] ."</td><td>". $rij['hoofdtsuk'] ."</td><td>&gt;</td><td>". $rij['cId'] ."</td><td>". $rij['categorie'] ."</td><td>&gt;</td><td>". $rij['iId'] ."</td><td>". $rij['item'] ."</td><td>". $icoon .'</td><td>'. $link .'</td></tr>';



This outputs a table with 107 rows and in some places I have the special characters.

Answer Source

You need to set the proper charset. Foreaxample if you want to set it in php use:

header( 'Content-Type: text/html; charset=UTF-8' ); 
// Should be on every file so easiest is to set it under session_start(); if you use sessions

If you want to set it in html use:

<meta charset="UTF-8"> <!-- Should be set in <header> -->
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download