I want to encode Danish characters before sending them to the database.
I am trying 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 when I try to send a row 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 data type of the fields in the table is UTF-8 ( utf8_unicode_ci ), so I have to encode my string using the same
This thread relates to my question: Detect encoding and do all UTF-8 .
However, I need to know how to encode any character in UTF-8 before inserting it into the database, otherwise I get an error message as above. I think I need to first determine which characters I get before putting them into the database.
source share