我正在尝试比较两个 string 但它总是返回 false 。两个 strings 都是相同的,但是当我检查它时,我进一步知道一个是 utf-8 (来自数据库/eloquent),另一个是从表单(ancii)提交的。主要问题是在数据库中 string 之间和之后有空格。我也尝试使用 mysql TRIM() 但失败了。任何铅我该怎么办?
我也尝试改变编码
iconv("UTF-8", "ISO-8859-1",str_replace(' ', '', $request->sentence))
尝试将 string 与 strcmp() 进行比较,但它永远不会返回 0
任何帮助表示赞赏,并感谢您的关注。
$sentence = AvailableSentence::
where('sentence_id', $request->sentence_id)
->with(['details'])
//->where
->first();
//var_dump(strcmp( str_replace(' ', '', $sentence->details->sentence) , str_replace(' ', '', $request->sentence) ));
//var_dump( iconv("UTF-8", "ISO-8859-1",str_replace(' ', '', $request->sentence)) );
//var_dump(mb_detect_encoding(' ', '', $sentence->details->sentence));
回答1
您可以在客户端设置它应该像的字符集:
<meta charset="utf-8">
或者
<form ... accept-charset="utf-8">