Erlend Anderson
Erlend Anderson

Reputation: 51

HTML elements in utf8 in a php file?

I'm having problems displaying unicode characters in a php file.

The thing is that the line <td>Märkus</td> and <td>Tooterühm</td> don't display the "ä" and "ü" characters. Any ideas? Thanks!

Here's the entire code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sisestamine</title>

</head>

<body>

<?php
header('Content-type: text/html; charset=utf-8');


session_start();

    echo 'Tere tulemast, '.$_SESSION['user']. '<br> <br>';




if(isset($_POST['save'])){


include 'config.php';



extract($_REQUEST);

$user = $_SESSION['user']; 


$query=mysql_query("insert into norse5_proov SET osakond='$osakond', soetusaasta='$soetusaasta', it_number='$it_number', tooteruhm='$tooteruhm', mudeli_nimetus='$mudeli_nimetus', sn='$sn', riigivara_nr='$riigivara_nr', inventaari_nr='$inventaari_nr', maja='$maja', ruum='$ruum', vastutaja='$vastutaja', markus='$markus', kasutajanimi='$user'") or die(mysql_error());


if($query){


echo "Andmed sisestatud";


}

}

?>


<form action='#' method='post' border='0'>

<table>
<br>
<tr>

<td>Osakond</td>

<td><input type='text' name='osakond' /></td>

</tr>

<tr>

<td>Soetusaasta</td>

<td><input type='text' name='soetusaasta' /></td>

</tr>

<tr>

<td>IT Number</td>

<td><input type='text' name='it_number' /></td>

</tr>

<tr>

<td>Tooterühm</td>

<td><input type='text' name='tooteruhm' /></td>

</tr>

<tr>

<td>Mudeli nimetus</td>

<td><input type='text' name='mudeli_nimetus' /></td>

</tr>

<tr>

<td>SN</td>

<td><input type='text' name='sn' /></td>

</tr>

<tr>

<td>Riigivara nr</td>

<td><input type='text' name='riigivara_nr' /></td>

</tr>

<tr>

<td>Inventaari nr</td>

<td><input type='text' name='inventaari_nr' /></td>

</tr>

<tr>

<td>Maja</td>

<td><input type='text' name='maja' /></td>

</tr>

<tr>

<td>Ruum</td>

<td><input type='text' name='ruum' /></td>

</tr>

<tr>

<td>Vastutaja</td>

<td><input type='text' name='vastutaja' /></td>

</tr>

<tr>

<td>Märkus</td>

<td><input type='text' name='markus' /></td>


<tr>

<td></td>

<td>

<input type='submit' value='Salvesta' name="save" />
<br>
<br>

<a href="update.php">Uuenda andmeid</a><br>
<a href="delete.php">Kustuta andmeid</a><br>
<a href="show_data.php">Kuva andmeid</a><br>
<br>
<a href="index.php">Algusesse...</a>


</td>

</tr>

</table>

</form>

</body>

</html>

The thing is that the line Märkus and Tooterühm don't display the "ä" and "ü" characters. Any ideas? Thanks!

Upvotes: 1

Views: 437

Answers (4)

Roopendra
Roopendra

Reputation: 7762

You should ensure the HTTP server headers are correct.

In particular, the header:

Content-Type: text/html; charset=utf-8

should be present.

The meta tag is ignored by browsers if the HTTP header is present. alternatively use HTML entities for the special characters here is link for html special character code.

Upvotes: 0

Martin
Martin

Reputation: 1822

Check how the fields are encoded in database. Might be the problem is there.

Upvotes: 0

Salvatorelab
Salvatorelab

Reputation: 11873

Check that the file is saved as UTF-8. Sometimes files are ANSI encoded, and thus even when you set your headers correctly UTF chars are not displayed.

So check both things:

  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  2. Your PHP file encoding.

Note: if the file is not encoded with UTF-8, and you change it, remember to check special characters again, as they may change when you save the file with the new format.

Upvotes: 2

Billy Moon
Billy Moon

Reputation: 58521

Might be because you set your headers after you output content. You need to call header before there is any output from your script, and you should also start your session before you send your headers. The start of the file should look like this...

<?php 
session_start();
header('Content-type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

...

Upvotes: 2

Related Questions