I have this code that works fine outside of Joomla, but once I put it into a Joomla Module, it does not properly encode. See
"Cura�ao - - converted:Cura?ao"
as an example. This should be
"Cura�ao - - converted:Curaçao"
when encoded properly.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
error_reporting(E_ERROR);
header('Content-Type: text/html; charset=utf-8' );
$includes_url = $_SERVER['DOCUMENT_ROOT'] . "/Joomla33/_Leagues/_includes/";
ini_set('default_charset', 'utf-8');
include_once($includes_url. "php/OpenDB.php");
$query = "SELECT * FROM chasiv_timezones.country ORDER BY country_name ASC";
$result = mysqli_query($conn, $query);
?>
Country:<select id='country' name='country'>
<option value=''>-- Select --</option>
<?php
while($data = mysqli_fetch_assoc($result)) {
echo $name = mb_convert_encoding($data['country_name'],'utf8');
if($data['country_code'] == $row['country']) { $sel = " selected"; } else { $sel = ""; }
?>
<option value="<?php echo $data['country_code']; ?>" <?php echo $sel; ?>><?php echo $name; ?></option>
<?php
}
?>
</select>
<?php
$query = "SELECT * FROM chasiv_timezones.country ORDER BY country_name ASC";
$result = mysqli_query($conn, $query);
if(!$result) {
exit("Unable to connect to database to get timezone countries. SQL:" . $query);
}
echo "<br />";
mysqli_set_charset($conn, 'utf8mb4');
while($data = mysqli_fetch_assoc($result)) {
echo $data['country_name'] . ' - ' . mb_check_encoding($data['country_name'],'utf8');
if(!mb_check_encoding($data['country_name'],'utf8')) {
echo " - converted:" . mb_convert_encoding($data['country_name'],'utf8') . '<Br />';
} else {
echo "<br />";
}
}
?>
JDatabase
class: docs.joomla.org/Selecting_data_using_JDatabase