Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP MongoDB->insert - fatal error with utf8

Tags:

php

mongodb

An annoying encoding error worries about a new dataset in a mongoDB insert and stops my script when there is a encoding issue?

       PHP Fatal error: Uncaught exception 'MongoException' with message 'non-utf8 string: ü'

How to fix the new dataset before the PHP driver breaks?

Is there a better idea than utf8_encode any string data, even those that are already utf8?

like image 878
ledy Avatar asked Jan 07 '13 22:01

ledy


2 Answers

Had the same issue. This works:

$string = mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
like image 161
Atul Yadav Avatar answered Oct 09 '22 16:10

Atul Yadav


utf8_encode() ( http://php.net/manual/en/function.utf8-encode.php ) since the default PHP encoding is still not utf8 yet I think (not sure about PHP 5.4).

like image 30
Sammaye Avatar answered Oct 09 '22 14:10

Sammaye