简体   繁体   中英

ASCII encoded unicode to SQL statement in PHP with mb_convert_encoding

I'm working with a file type that is comprised of ASCII characters only. Other characters are encoded. Two byte characters are preceded with \\X2\\ and followed by \\X0\\ and four byte characters use \\X4\\ and \\X0\\ . I can find these easily enough but I'm not sure how to then handle them.

eg the character ø is given as \\X2\\00F8\\X0\\ .

My whole string I'm looking for is 100 mm\\X2\\00F8\\X0\\ .

How can I get that to a string that I could then say insert into my DB?

I figure I need to use mb_convert_encoding()

But I'm not sure which encoding I want to go to and from.

Any ideas?

Put simply I have "100 mm\\X2\\00F8\\X0\\" and I want to output that as "100 mmø"

It depends on SQL server you are using. For example for MySQL you can use mysqli_real_escape_string

This method automatically takes encoding from your sql connection so it is safe to use.

I would pass raw value 100m ø.

so all I needed was hex2bin('00F8')

Then utf8_encode(...) to get it from utf-16 to utf 8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM