Laravel 5.1 codification problems. Getting � - utf-8

I'm having problems with utf-8 and Laravel 5. I know is a popular problem, but I read and read without success. This is what I have:
Tables and columns in database (mysql) are configured as utf8_unicode
So, in Laravel, in config/database.php
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
In my forms I always use
accept-charset="UTF-8"
And in the head
meta charset="utf-8"
Content-Type:text/html; charset=UTF-8
My php files are encoded in utf-8
But I'm still getting (around 0.1%) of characters as �
Is there any way to solve this? I'm doing something wrong?
Thanks.

Related

Laravel 5.2 Maatwebsite Excel::load not parsing Japanese characters

I'm using Maatwebsite excel v ~2.1.0 for my Laravel 5.2 project. My problem is that the japanese characters are not rendered as seen the photo below. As you can see, I have 23 heading rows and the displayed data only are only English characters. Columns that uses Japanese characters are null.
This is my data in my CSV file.
This is my approach in loading the CSV file:
Excel::load(request()->file('file'), function($reader) {
$results = $reader->all();
dd($results);
});
What should I change to make the Japanese characters readable?
Okay after exploring more, I found out the answer. In excel.php file, I changed 'to_ascii' => true, to 'to_ascii' => false and my problem is fixed. Hope this helps someone in the near future.

I read from remote server some ugly letters

In Laravel 5.8 / vuejs 2.6 I make search from remote server and outputting readed data I see some ugly symbols :
https://prnt.sc/p2nb2w
I suppose these(or part of them) are some arabic letters. I read the data with curl, having headers :
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
On my site I use utf-8 and Cera-GR fonts.
Dumping readed data for printscreen with examples above I see in kate editor next text pieces:
[Description] => 🌎🌍🌏 Moroccan Travel lover living in Paris/Dubai 📍Dubai
[FullName] => ☕️💈pdl - Est. 2018 💈☕️
[Description] => Latin American Restaurant🍴
Pisco Bar& Lounge 🍸
Members' Club✨
+971(0)43169600 ☎️ reservations#coyarestaurant.ae 💌
I am not sure what can I do here? What kind of symbols are there ? Change the fonts or clear some symbols?
If just clear them, by which rules?
Thanks!
You could get rid of them from the string in Javascript, if that's what you'd like to achieve. Run them through this:
removeIllegalCharacters(string) {
string.replace(/[^\w\s]/gi, '').trim()
}
This will retain your spaces, but .trim() will ensure you don't have any leading or trailing spaces on the string.

How to fix wrong text encoding (ðø)?

How to fix text encoding: ðø? I'm using Laravel and MySQL database.
I tried
mb_convert_encoding($var,$to,$from);
But I don't know encoding from and to.
Create the database with UTF-8 encoding like this:
CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
If you do this, you should never need to convert anything. To ensure incoming user data has the right coding, make sure to set the encoding in the head tag:
<head>
<meta charset="UTF-8">
</head>
If you work with existing data, there is no way around figuring out what encoding it has before converting it with mb_convert_encoding.

mysql charset latin1 into utf-8 conversion issue

My client's web app has large database which millions of records. All table's encoding is latin1.
When I fetch some text field which holds huge data and mail that string some strange haracter issue comes. Such when I recieve email spaces are converted into this character Â.
It is not premissible to change the DB encoding.
I tried the following PHP function but no outcome ;(
$msg = mb_convert_encoding($msg, "UTF-8", "latin1");
Please help
I would check for the encoding php thinks it is
echo mb_detect_encoding($str);
And then do
iconv("detectedEncoding", "UTF-8", $str);
Or if iconv is not installed, check if your encoding was right in your solution. ;)

Ruby Thin/Rack strange multibyte characters behavior

The question was re-written.
I'm working on a simple web framework, and encountered a strange behavior from either Rack or the Thin server I'm using.
I tried to simplify the config.ru file as much as I could to gain the following code which reproduces the strange problem:
app = Proc.new do |env|
content = "<p>عربي</p>"
headers = {'Content-Type' => 'html/text; charset=utf-8', 'Content-Length' => content.length.to_s}
[200, headers, [content]]
end
run app
The code above is a normal Rack process, with the content a HTML paragraph which contains an Arabic word of four letters. Now, running Thin server: thin start, I was waiting for the source of the web page to be:
<p>عربي</p>
While it turned to be:
<p>عربي
Only, without the closing tag. The server works correctly if I inserted an English word instead of the Arabic one, so I concluded that the problem is related to the encoding or multibyte characters of Arabic.
I'm using Ruby 1.9.2. The encoding of the file is UTF-8. And Ruby works well if I just try puts "<p>عربي</p>" in the console without the Rack or Thin server.
So, the problem is simply disappearing of a number of characters after the Arabic text when using Rack and Thin + the number of disappearing characters == the number of the Arabic characters in the text.
Any thoughts?
Does 'Content-Length' => content.bytesize.to_s improve things?
Well, you have to tell Ruby that the string has Arabic in it. Use the force_encoding method with whatever encoding supports those Arabic characters:
str.force_encoding("nameOfArabicEncoding")

Resources