PHP function to convert special characters to unicode(UTF-16)

Jmh2013

Is there a PHP function that can take a string and convert any special characters to unicode. Similar to htmlspecialchars() or UTF8_encode().

For example in the string: "I think Bob's going too".

I would need the apostrophe or single right quote unicode in place of the apostrophe in "Bob's". So then after conversion the string should read: "I think Bob\u2019s going too".

I need this for use in a PHP script that prints into a javascript function.

Using \ to escape or ' does not work, it stops the script from running. I am trying to use Flowplayers Playist plugin. The only way it seems I can have a string with special characters is if they are in unicode.

Here is a JSFIDDLE to play around with and see what I mean when I say it doesn't work. Just replace \u2019 with ' or something similar and click to have the song play. The media player just goes black and doesn't play anything, whereas if you leave it with \u2019 then it plays fine.

Any help is appreciated.

fpietka

I think json_encode() is the function you are looking for here.

The following code:

$string = "I think Bob’s going too";
print_r(json_encode($string));

will output:

"I think Bob\u2019s going too"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

convert special characters in table ascii php

From Dev

How to convert special characters in xml using php?

From Dev

Convert html special characters into numeric codes with PHP

From Dev

PHP: chr Function Issue with Special characters

From Dev

Convert HTML entities and special characters to UTF8 text in PHP

From Dev

remove special characters in php

From Dev

Counting special characters with PHP

From Dev

php and special characters

From Dev

PHP JSON Special Characters

From Dev

Removing special characters php

From Dev

Escaping special characters in "str_replace" PHP function

From Dev

PHP function for converts html entities back to html special characters

From Dev

Escaping special characters in "str_replace" PHP function

From Dev

Convert word special characters in VBS

From Dev

Convert a string to unicode with special characters

From Dev

Is there a way to convert special characters to normal characters in Swift?

From Dev

Convert special Characters to Unicode Escape Characters Scala

From Dev

Regex for followed by special characters in PHP

From Dev

Testing special characters with PHP Unit

From Dev

Escape elasticsearch special characters in PHP

From Dev

PHP - format special characters and display

From Dev

Testing special characters with PHP Unit

From Dev

PHP / MySQL special characters issue

From Dev

scandir in php with special (hungarian) characters

From Dev

Encode accents and special characters PHP

From Dev

PHP Regular Expression special characters

From Dev

Finding and replacing special characters in php

From Dev

PHP / MySQL special characters issue Â

From Dev

PHP and MySQL special characters error

Related Related

HotTag

Archive