0

I have a GPS which returns address in a UNICODE string format, for example:

0053 004F 0053 0028 004C 0029 003A 0053 0068 0069 006D 0069 006E 0020 0046 0061 0069 
0072 0079 006C 0061 006E 0064 0020 0057 0065 0073 0074 0020 0052 0064 002C 0048 0075 
0069 0063 0068 0065 006E 0067 002C 0048 0075 0069 007A 0068 006F 0075 002C 0047 0075 
0061 006E 0067 0064 006F 006E 0067 0028 004E 0032 0033 002E 0031 0031 0031 002C 0045 
0031 0031 0034 002E 0034 0031 0031 0029 004E 0065 0061 0072 0062 0079

should be (according to this website: http://rishida.net/tools/conversion/)

S O S ( L ) : S h i m i n   F a i r y l a n d   W e s t   R d , 
H u i c h e n g , H u i z h o u , 
G u a n g d o n g ( N 2 3 . 1 1 1 , E 1 1 4 . 4 1 1 ) N e a r b y

How can I achieve this in PHP?

3 Answers 3

1

I took @user1978142 code and modified it a bit so it would display fine on my MAC terminal.

Here is a working version:

<?php

$string = '0053 004F 0053 0028 004C 0029 003A 0053 0068 0069 006D 0069 006E 0020 0046 0061 0069 
0072 0079 006C 0061 006E 0064 0020 0057 0065 0073 0074 0020 0052 0064 002C 0048 0075 
0069 0063 0068 0065 006E 0067 002C 0048 0075 0069 007A 0068 006F 0075 002C 0047 0075 
0061 006E 0067 0064 006F 006E 0067 0028 004E 0032 0033 002E 0031 0031 0031 002C 0045 
0031 0031 0034 002E 0034 0031 0031 0029 004E 0065 0061 0072 0062 0079';

$final_string = '';
foreach(explode(' ', $string) as $string) {
    $final_string .= chr('0x'.$string);
}

echo "\n".$final_string."\n";
?>
Sign up to request clarification or add additional context in comments.

Comments

0

You need to explode each string first, then append &#x on each strings so that you can utilize html_entity_decode(). Consider this example:

$string = '0053 004F 0053 0028 004C 0029 003A 0053 0068 0069 006D 0069 006E 0020 0046 0061 0069 
0072 0079 006C 0061 006E 0064 0020 0057 0065 0073 0074 0020 0052 0064 002C 0048 0075 
0069 0063 0068 0065 006E 0067 002C 0048 0075 0069 007A 0068 006F 0075 002C 0047 0075 
0061 006E 0067 0064 006F 006E 0067 0028 004E 0032 0033 002E 0031 0031 0031 002C 0045 
0031 0031 0034 002E 0034 0031 0031 0029 004E 0065 0061 0072 0062 0079';

$final_string = '';
foreach(explode(' ', $string) as $string) {
    $final_string .= html_entity_decode('&#x' . trim($string));
}

echo $final_string;
// SOS(L):Shimin Fairyland West Rd,Huicheng,Huizhou,Guangdong(N23.111,E114.411)Nearby

2 Comments

Thanks, that worked. Anyway to convert the html entities to something that can be read at a UNIX terminal? I tried converting to utf-8 with no success so far...
@MagisterMundus in this case its in HTML format, but in terms of CLI, its another story, since this unicode equivalent is for html only, yes. naturaly this wont work, i think for cli its something like \u0053 something, you could google it yourself too since i dont memorize them all
0

Possible Duplicate:

How to get the character from unicode code point in PHP?

PHP: Convert unicode codepoint to UTF-8

If I understand correctly, you can view these topics on stackoverflow.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.