0

I have a string which contains bullets • in the following format:

$string = "Yay bullets!!\n\\u2022\n\\u2022\n\\u2022\n\\u2022\n\\u2022\n#somany";

I need to echo the string displaying the bullets. The closest I've come to printing this out is by making $string = "\u2022"; and then echoing json_decode('"' . $string . '"'); which prints the bullet just fine.

When I try to do the same to the full $string I get no result at all and no error.

Here are some things I have tried with their resulting output:

$raw = htmlspecialchars("Yay bullets!!\n\\u2022\n\\u2022\n\\u2022\n\\u2022\n\\u2022\n#yes", ENT_QUOTES);

echo $raw;

Result:

Yay bullets!!
\u2022
\u2022
\u2022
\u2022
\u2022
#yes

When I try:

echo mb_convert_encoding($raw, 'UTF-8', 'HTML-ENTITIES');

Result: Same as above. No change.

When I try:

echo json_decode('"' . $raw . '"');

Result: No output.

When I try:

echo mb_convert_encoding($raw, 'UTF-8', 'UTF-16BE');

Result: 奡礠扵汬整猡ℊ屵㈰㈲ੜ甲〲㈊屵㈰㈲ੜ甲〲㈊屵㈰㈲ਣ祥

I would really appreciate help figuring out how to output this properly.

Thanks.

EDIT

In addition to bullets, I am also failing to print emoji reference codes such as \\ud83d\\udc93. Reference here: http://emojipedia.org/face-with-tears-of-joy/

1 Answers1

0

you can do like this. It working for both. please check

 function decodeEmoticons($src) {
    $replaced = preg_replace("/\\\\u([0-9A-F]{1,4})/i", "&#x$1;", $src);
    $result = mb_convert_encoding($replaced, "UTF-16", "HTML-ENTITIES");
    $result = mb_convert_encoding($result, 'utf-8', 'utf-16');
    return $result;
}
$r = "Yay bullets!!\n\\u2022\n\\u2022\n\\u2022\n\\u2022\n\\u2022\n#somany";
echo decodeEmoticons($r);
$src = "\u263a\ud83d\ude00\ud83d\ude01\ud83d\ude02\ud83d\ude03";
echo decodeEmoticons($src);
ravi2432
  • 211
  • 2
  • 8
  • code will only work if platform have mbstring installed:- https://stackoverflow.com/a/19728019/4248328 – Alive to die - Anant Jul 06 '17 at 06:39
  • This works great for the bullet example. But fails when trying to convert unicode emoji like this `\\ud83d\\udc93` as it outputs ��. This is the emoji reference http://emojipedia.org/beating-heart/ –  Jul 06 '17 at 06:46