简体   繁体   中英

How to convert special characters like “ü” from a SQL DB using PHP to display in a browser?

I am not familiar with the concept of encoding. That's likely my main problem.

However, I just want to be able to take values that are already in my database (SQL Server) and display them in the browser. Some of those characters are from the German alphabet like ä, ö, ü. They display as �� instead.

I've tried lots of variations of php conversion hoping one of them would properly convert the value to the equivalent HTML entity so that it would then display properly in the browser. I know I can replace my text value with the HTML entity and then of course is displays correctly.

Here are some attempts:

$Text = "ü"

// echo mb_convert_encoding($Text,"SJIS");
// echo iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $Text);
// echo htmlentities($Text, ENT_COMPAT, 'UTF-8');
// echo htmlentities($Text, ENT_NOQUOTES); 

I know there are many other questions that seem related but none that have worked so far. Any help would be much appreciated.

Do I understand it correctly that ONLY the database entries are wrong???

Checkif the üäö do work on the page if you insert them with echo"" and /or with html. if these work - then there is a different problem.

The database table & database probably have the wrong encoding and

My suspicion:

The connection to the database can be the problem. Check if this is configured as "utf-8".

The latter depends on your database eg für mysql i have the following code directly after the mysql_connect

mysqli_set_charset($link, "utf8");

https://www.php.net/manual/de/mysqli.set-charset.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