PHP; Passing a UTF-8 string via include/require [duplicate] - php

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 7 years ago.
I have the following function;
function generateFirstName(){
$firstNameArray = array("Thomáš ","Lukáš ");
$firstNameKey = mt_rand(0,1);
$firstName = $firstNameArray[$firstNameKey];
return $firstName;
}
When the function is called on the same page the UTF-8 format outputs fine, but when it is called from a functions.php (that is REQUIRED in the INCLUDED head.php) the UTF-8 format doesn-t arrive and i get the dreaded black diamond with white question mark.
What do I need to do to pass the strings?

Check every required or included files encoding. They all must be in UTF-8 to work together. You have to be sure about every file, that can be included from functions.php and other files.

Each file must be encoded in utf8

Related

How do I translate these weird UTF-8 "from" strings in e-mail context? [duplicate]

This question already has answers here:
decode a quoted printable message in php
(1 answer)
Decoding "=C3=A4" in a string
(1 answer)
Closed 3 years ago.
Receiving e-mails, I end up with "complete from strings" such as this one:
$test = '=?UTF-8?Q?Test=C3=B6p?= <no-reply#Testöp.tld>';
How do I get rid of the "=?UTF-8?" nonsense? Obviously I don't mean to just string-replace it, but to convert it properly to an actual UTF-8 string. It's supposed to be something like:
$test = 'Testöp <no-reply#Testöp.tld>';
I don't know why I get this in the first place, but I bet there is a simple function to do it somewhere in PHP.
Note: It's not utf8_decode()! That one does nothing to that string!

È char saves as ? in file php [duplicate]

This question already has answers here:
How to set HTTP header to UTF-8 using PHP which is valid in W3C validator
(7 answers)
UTF-8 all the way through
(13 answers)
Reference: Why are my "special" Unicode characters encoded weird using json_encode?
(1 answer)
Closed 3 years ago.
I'm trying to save string to a file but we're getting a ? instead of the char.
What would be the best way of being able to save chars like "È" to a file as a readable char.
And also being able to html_decode($str) the string in php?
--UPDATE -----
adding "mysql:charset=utf8mb4;" to the PDO database connection fixed the problem.
-- STILL ENCOUNTERING PROBLEMS --
even though when I echo the string to the terminal now I can see it properly in the terminal. But once I save it to the file I get this:
CAF\u00c9
-- FILE SAVE EXAMPLE --
$jsonStr = '';
... process to query db and get string with utf-8 connection
and loop over all results and append a json_encoded string to each new line
loop start
$jsonStr .= json_encode($array) . "\n";
loop end
file_put_contents($path, $jsonStr);
-- ANSWER --
json_encode needs the "JSON_UNESCAPED_UNICODE" flag as a second param

PHP utf8_decode some characters decode correctly some not [duplicate]

This question already has answers here:
strange character encoding of stored data , old script is showing them fine new one doesn't
(2 answers)
UTF-8 all the way through
(13 answers)
Closed 4 years ago.
Okay, something went wrong in our database and now all the content from Chinese, Turkish etc. language is messed up (wrong characters). I'm trying to create a PHP script to convert it. Yes, SET NAMES utf8 is executed, everything is utf8mb4_general_ci and the PDO connection has charset utf8.
For example, we got the following text:
Bizimle iletişime geçin
Which is supposed to be:
Bizimle iletişime geçin
Now, if I display the output from the database, it displays the first line what we got in our database (Bizimle iletişime geçin). Then, I use this line:
die(utf8_decode('Bizimle iletişime geçin'));
The output of it is:
Bizimle ileti�?ime geçin
So the ç gets decoded correctly but the ş doesn't.
I tried going to an online utf8-decoder (https://software.hixie.ch/utilities/cgi/unicode-decoder/utf8-decoder) and if I try to decode ÅŸ it does show the ş correctly.

Encoding converting PHP [duplicate]

This question already has an answer here:
Encoding detecting php
(1 answer)
Closed 8 years ago.
I need help with encoding :(
I have parsed string from site: Ëè÷íûå âñòðå÷è
My site is in UTF-8 encoding.
How to convert parsed string to encoding of my site?
On this site artlebedev.ru/tools/decoder
When I click on "Расшифровать" button, I get right result: Личные встречи.
this does not work you say?
echo iconv("iso-8859-5","utf-8","Ëè÷íûå âñòðå÷è");
then are you sure your file is utf8 also?
try this
echo iconv("cp1251","utf8",iconv("utf8","cp1252","Ëè÷íûå âñòðå÷è"));

php include ÅÄÖ = ??? / UTF8 problem [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 2 years ago.
index.php
<?php
include("header.php");
?>
header.php
<?php
echo"<a href='add.php'>Lägg Till</a>";
?>
result
L?gg Till
The document is utf8 within the head tags and all, it's a php thing, the problem only occurs when i get text from include, i cannot have ÅÄÖ in included php files , how do i make it work?
Save these files in utf-8 too
when sending text to server with accents letters use always ut8_encode, in you case:
echo utf8_encode("<a href='add.php'>Lägg Till</a>");
I have the same problem and this on solves them.
Besides saving the file in UTF-8 you could also check the "default_charset" configuration in the php.ini file.

Categories