Laravel UTF-8 转数据库

Laravel UTF-8 To Database(Laravel UTF-8 转数据库)
本文介绍了Laravel UTF-8 转数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 Eloquent 将一个新人保存()到我的数据库中.人名包含一个特殊字符 é 并且它不是提交.这是我的步骤和结果.

I'm using Eloquent to save() a new person into my database. The persons name contains a special character é and it's not submitting. Here are my steps and the results.

echo Input::get('firstname'); // Miguél

这给了我这个

当我开始使用 eloquent 时,会发生以下情况.

When i start using eloquent the following happens.

$person = new Person();
echo $person->firstname = Input::get('firstname'); 

结果如下

知道可能出了什么问题吗?这些是我在 laravel 中的配置设置

Any idea what might be going wrong? These are my config settings in laravel

这是我在 phpmyadmin 中的数据库

And this is my database in phpmyadmin

谢谢

推荐答案

我认为它与数据库没有任何共同之处.

I don't think it has anything common with database.

使用时:

$person = new Person();
echo $person->firstname = Input::get('firstname'); 

你在这里不使用数据库.您只需将属性分配给 Person 类(可能使用 Eloquent),但您没有将任何内容放入数据库并从数据库中获取任何内容,因此编码问题不可能与数据库本身有任何共同之处

you don't use database in here. You just assign properties to Person class (that probably uses Eloquent) but you don't put anything into database and get anything from database so it's not possible that the encoding problem has anything in common with database itself

我认为潜在的问题 - 您已经在 Person 类中为 firstname 属性定义了mutator,因为它是小写的(当你从 Input 中得到它时,它是大写的) 所以你可能使用了一些像 strtolower 这样的函数,你应该使用 mb_strtolower 来转换 UTF-8 字符串而不会有问题.

Potential problem in my opinion - you have defined mutator in Person class for firstname attribute because you have it in lowercase (when you get it from Input it's with capital letter) so you probably use some function like strtolower and you should use mb_strtolower to convert UTF-8 strings without a problem.

这篇关于Laravel UTF-8 转数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)