I want to encode Danish characters before sending them to database.
I try to apply this function to them:
private function process_array_elements(&$element){
$element = utf8_encode($element);
$element = strip_tags( $element );
$element = strtolower ( trim ( $element ) );
$element = mysql_real_escape_string($element);
return $element;
}
Like this:
$this->check_line_two = $this->process_array_elements($e);
Now, whenever I try to send the string to the database:
mysql_query("SET NAMES 'utf8'");
$query="INSERT INTO result_scanned
SET line_one= '$this->check_line_one',
line_two='$this->check_line_two',
line_three='$this->check_line_three',
advert_id='$this->advert_id',
scanned='$this->scan_result'";
I get this:
Incorrect string value: '\xE3\x83\xE2\xB8r ...' for column 'line_three' at row 1
The datatype of the fields in the table are UTF-8 (utf8_unicode_ci
), so I must encode my string using the same
This thread is related to my question: Detect encoding and make everything UTF-8.
However, I need to know how to encode any character to UTF-8, before inserting it to the database, otherwise, I get an error as the one aforementioned. I think I need to identify first what kind of characters I am receiving before putting them into database.