/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] addslashes to unicode

I am using file_get_contents to populate a string with content. I am trying to safely pass it to JavaScript as a string without data corruption. I am currently using the rawurlencode and unescape combo. Unfortunately unicode characters are being lost along the way since some of the files contain unicode characters like ש which is “u05e9” in JavaScript. If file_get_contents reads such a unicode character I need it to convert to the second form before echoing it to JavaScript. Non-unicode characters can be represented by “x93” which is the same as “u0093” however saving two extra digits.

Any suggestions how to perform this string conversion with PHP? I’m thinking some kind of loop yet chr and ord are for ASCII and I’m trying to work with Unicode…

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterauthorFeb 06.2007 — Aaah forget it. http://mike.teczno.com/JSON/JSON.phps
<i>
</i>&lt;script type="text/javascript"&gt;
&lt;?php
include("json.php");
$json = new Services_JSON();
$str=file_get_contents("q.txt");
echo "alert(".$json-&gt;encode($str).")";
?&gt;
&lt;/script&gt;
×

Success!

Help @Ultimater spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...