Convert unicode special characters to UTF-8
I have problem with converting unicode characters to utf-8.
Here is my code:
<?php
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
$utf8string = html_entity_decode(preg_replace("/U+([0-9A-F]{4})/", "&#x\1;", $unicode), ENT_NOQUOTES, 'UTF-8');
echo $utf8string;
?>
And it gives me below:
u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d
What did i do wrong ? any advice ?
php unicode
add a comment |
I have problem with converting unicode characters to utf-8.
Here is my code:
<?php
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
$utf8string = html_entity_decode(preg_replace("/U+([0-9A-F]{4})/", "&#x\1;", $unicode), ENT_NOQUOTES, 'UTF-8');
echo $utf8string;
?>
And it gives me below:
u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d
What did i do wrong ? any advice ?
php unicode
see here: php.net/manual/en/… and here: stackoverflow.com/questions/1805802/…
– Jeff
Nov 22 '18 at 2:24
Possible duplicate of PHP: Convert unicode codepoint to UTF-8
– Jeff
Nov 22 '18 at 2:26
add a comment |
I have problem with converting unicode characters to utf-8.
Here is my code:
<?php
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
$utf8string = html_entity_decode(preg_replace("/U+([0-9A-F]{4})/", "&#x\1;", $unicode), ENT_NOQUOTES, 'UTF-8');
echo $utf8string;
?>
And it gives me below:
u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d
What did i do wrong ? any advice ?
php unicode
I have problem with converting unicode characters to utf-8.
Here is my code:
<?php
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
$utf8string = html_entity_decode(preg_replace("/U+([0-9A-F]{4})/", "&#x\1;", $unicode), ENT_NOQUOTES, 'UTF-8');
echo $utf8string;
?>
And it gives me below:
u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d
What did i do wrong ? any advice ?
php unicode
php unicode
asked Nov 22 '18 at 2:20
Kh Shuren-ErdeneKh Shuren-Erdene
163114
163114
see here: php.net/manual/en/… and here: stackoverflow.com/questions/1805802/…
– Jeff
Nov 22 '18 at 2:24
Possible duplicate of PHP: Convert unicode codepoint to UTF-8
– Jeff
Nov 22 '18 at 2:26
add a comment |
see here: php.net/manual/en/… and here: stackoverflow.com/questions/1805802/…
– Jeff
Nov 22 '18 at 2:24
Possible duplicate of PHP: Convert unicode codepoint to UTF-8
– Jeff
Nov 22 '18 at 2:26
see here: php.net/manual/en/… and here: stackoverflow.com/questions/1805802/…
– Jeff
Nov 22 '18 at 2:24
see here: php.net/manual/en/… and here: stackoverflow.com/questions/1805802/…
– Jeff
Nov 22 '18 at 2:24
Possible duplicate of PHP: Convert unicode codepoint to UTF-8
– Jeff
Nov 22 '18 at 2:26
Possible duplicate of PHP: Convert unicode codepoint to UTF-8
– Jeff
Nov 22 '18 at 2:26
add a comment |
1 Answer
1
active
oldest
votes
At the very least your regular expression is looking for an uppercase U
, while all your escape sequences use lower-case.
But your conversion script goes from javascript-escaped unicode characters, to HTML entities, back to a PHP string. This might be a saner solution (for this string):
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
echo json_decode('"' . $unicode . '"');
Be careful though, as this might break if the input string contains newlines or quotes.
Nice but i have question when incoming data are dynamically many type of texts its works ?
– Kh Shuren-Erdene
Nov 22 '18 at 2:36
Check the last sentence in my answer. There are certain characters that would make this invalid JSON.
– Evert
Nov 22 '18 at 2:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423015%2fconvert-unicode-special-characters-to-utf-8%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
At the very least your regular expression is looking for an uppercase U
, while all your escape sequences use lower-case.
But your conversion script goes from javascript-escaped unicode characters, to HTML entities, back to a PHP string. This might be a saner solution (for this string):
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
echo json_decode('"' . $unicode . '"');
Be careful though, as this might break if the input string contains newlines or quotes.
Nice but i have question when incoming data are dynamically many type of texts its works ?
– Kh Shuren-Erdene
Nov 22 '18 at 2:36
Check the last sentence in my answer. There are certain characters that would make this invalid JSON.
– Evert
Nov 22 '18 at 2:50
add a comment |
At the very least your regular expression is looking for an uppercase U
, while all your escape sequences use lower-case.
But your conversion script goes from javascript-escaped unicode characters, to HTML entities, back to a PHP string. This might be a saner solution (for this string):
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
echo json_decode('"' . $unicode . '"');
Be careful though, as this might break if the input string contains newlines or quotes.
Nice but i have question when incoming data are dynamically many type of texts its works ?
– Kh Shuren-Erdene
Nov 22 '18 at 2:36
Check the last sentence in my answer. There are certain characters that would make this invalid JSON.
– Evert
Nov 22 '18 at 2:50
add a comment |
At the very least your regular expression is looking for an uppercase U
, while all your escape sequences use lower-case.
But your conversion script goes from javascript-escaped unicode characters, to HTML entities, back to a PHP string. This might be a saner solution (for this string):
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
echo json_decode('"' . $unicode . '"');
Be careful though, as this might break if the input string contains newlines or quotes.
At the very least your regular expression is looking for an uppercase U
, while all your escape sequences use lower-case.
But your conversion script goes from javascript-escaped unicode characters, to HTML entities, back to a PHP string. This might be a saner solution (for this string):
$unicode = 'u0411. u0426u044du0446u044du0433u0441u04afu0440u044du043d';
echo json_decode('"' . $unicode . '"');
Be careful though, as this might break if the input string contains newlines or quotes.
answered Nov 22 '18 at 2:32
EvertEvert
40.6k1569123
40.6k1569123
Nice but i have question when incoming data are dynamically many type of texts its works ?
– Kh Shuren-Erdene
Nov 22 '18 at 2:36
Check the last sentence in my answer. There are certain characters that would make this invalid JSON.
– Evert
Nov 22 '18 at 2:50
add a comment |
Nice but i have question when incoming data are dynamically many type of texts its works ?
– Kh Shuren-Erdene
Nov 22 '18 at 2:36
Check the last sentence in my answer. There are certain characters that would make this invalid JSON.
– Evert
Nov 22 '18 at 2:50
Nice but i have question when incoming data are dynamically many type of texts its works ?
– Kh Shuren-Erdene
Nov 22 '18 at 2:36
Nice but i have question when incoming data are dynamically many type of texts its works ?
– Kh Shuren-Erdene
Nov 22 '18 at 2:36
Check the last sentence in my answer. There are certain characters that would make this invalid JSON.
– Evert
Nov 22 '18 at 2:50
Check the last sentence in my answer. There are certain characters that would make this invalid JSON.
– Evert
Nov 22 '18 at 2:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423015%2fconvert-unicode-special-characters-to-utf-8%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
see here: php.net/manual/en/… and here: stackoverflow.com/questions/1805802/…
– Jeff
Nov 22 '18 at 2:24
Possible duplicate of PHP: Convert unicode codepoint to UTF-8
– Jeff
Nov 22 '18 at 2:26