what are the settings that i need to fix in php.ini, apache to show utf8 encoded text stored in oracle db to be displayed properly in a web page?
things i have done:
- default charset settings to utf8
- added explicit encoding in oci_connect
sample code:
<?php
function remove_utf8_bom($text)
{
$bom = pack('H*','EFBBBF');
$text = preg_replace("/^$bom/", '', $text);
return $text;
}
?>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"></meta>
</head>
<?php
echo getenv('NLS_LANG');
echo '<br/>';
putenv("NLS_LANG=AMERICAN_AMERICA.UTF8");
echo getenv('NLS_LANG');
echo '<br/>';
header('Content-Type: text/html; charset=UTF-8');
$conn = oci_connect('xxx', 'xxx', 'xxx', 'AL32UTF8');
if (!$conn) {
$e = oci_error();
echo "Connection failed: " . $e['message'];
exit;
}
// Set the NLS_LANG for the session
oci_execute(oci_parse($conn, "ALTER SESSION SET NLS_LANGUAGE='AMERICAN'"));
oci_execute(oci_parse($conn, "ALTER SESSION SET NLS_TERRITORY='AMERICA'"));
//oci_execute(oci_parse($conn, "ALTER SESSION SET NLS_CHARACTERSET='AL32UTF8'"));
oci_set_client_info($conn, "NLS_LANG=AMERICAN_AMERICA.AL32UTF8");
//mb_internal_encoding('UTF-8');
$query = 'SELECT * FROM FMS_BERUJU';
$stid = oci_parse($conn, $query);
oci_execute($stid);
while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
//var_dump($row);
$item = $row['FB_OFFICE_HEAD_NEP'];
//$item = str_replace(0xFEFF, "", $item, 1);
$item = remove_utf8_bom($item);
echo 'Office Head Nepali: '.htmlspecialchars($item, ENT_QUOTES, 'UTF-8') ."<br>n";
echo 'Office Head Nepali: '.mb_convert_encoding($item, 'UTF-8', 'auto') ."<br>n";
echo 'Office Head Nepali: '.$row['FB_OFFICE_HEAD_NEP']."<br>n";
echo 'Office Head Nepali: '.$item."<br>n";
echo 'Office ID: '.$row['FB_OFFICE_ID']."<br>n";
echo 'Office Fiscal Year: '.$row['FB_FISCAL_YEAR']."<br>n";
echo "<br>n";
echo "<br>n";
}
oci_free_statement($stid);
oci_close($conn);
output:
शà¥à¤°à¥€ कृषà¥à¤£ सिंह बसà¥à¤¨à¥‡à¤¤ / शà¥à¤°à¥€ सागर जà¥à¤žà¤µà¤¾à¤²à¥€