user1711383
user1711383

Reputation: 828

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.

e.g. 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ø"

Upvotes: 0

Views: 619

Answers (2)

user1711383
user1711383

Reputation: 828

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

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

Upvotes: 0

Martin
Martin

Reputation: 613

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 ø.

Upvotes: 0

Related Questions