简体   繁体   中英

UTF from included file - PHP

I am including my lang from separate file. As it's translate I need it to be code in UTF8, how ever i try it display D tum vytvorenia pr padu instead of Datum vytvoření případu

It looks like:

<html>
<head>
<meta charset="utf-8"> 
</head>
<body></body>
</html>

<?php
header('Content-Type: text/html; charset=utf-8');
$lang = array();

//All
$lang['YES'] = 'Áno';
$lang['NO'] = 'Nie';
$lang['NOT_AVALIABLE'] = 'Nie je k dispozícii';
$lang['CURRENCY'] = 'Mena';
.........

After that i just call it in class like:

  public function fetchByVinAxnmrss($con) {
     $success = false;
    include_once 'languages/'.$lang_file; 
     try{
            $sql = "SELECT * FROM axnmrs_cases WHERE vin = :vin ORDER BY date_created DESC LIMIT 60";
            $stmt = $con->prepare( $sql );
            $stmt->bindValue( "vin", $this->vin, PDO::PARAM_STR );
            $stmt->execute();
                while ($row = $stmt->fetch()){
                 echo  "<dt>".$lang['AXNMRS_CASE_CREATED_DATE']."</dt>";

What i try:

  • Class UTF8 is correct becuase it's working there if i just write
    directly the words without including lang text
  • All Files are saved with UTF-8 coding
  • Try to use Meta adn PHP for set UTF8 chars

I don't really know what else i can try.

you can use htmlentities function before display string.

$encodedString  = htmlentities($badString,ENT_QUOTES | ENT_IGNORE | ENT_SUBSTITUTE | ENT_DISALLOWED | ENT_HTML401 | ENT_XML1 | ENT_XHTML | ENT_HTML5, "ISO-8859-1");

For european words you need to encode string with ISO-8859-1 for othre languge characters you can refer Supported charsets table on this php reference

http://php.net/manual/en/function.htmlentities.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM