/    Sign up×
Community /Pin to ProfileBookmark

PHP – Printing Unicode HTML Source

Hi,

I’m experimenting to display unicode html source as following, but it displays boxes instead of actual unicode characters.

[CODE]

<?php

print “<HTML><HEAD><META http-equiv=’Content-Type’ content=’text/html; charset=UTF-8′></HEAD><BODY>”;

$data = file_get_contents(‘http://www.google.com/search?&hl=ur&q=%D8%A7%D9%84%D8%B4%D8%B1%D9%8A%D8%B9%DB%81’);
print $data;

print “</BODY></HTML>”;

?>

[/CODE]

What could be the reason?

Appreciated…

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@dk_zero-coolMar 20.2010 — You are asuming that the content you get from the link, is in Unicode. The meta tag you insert forces the browser to handle all text as UTF-8. It will not however, convert into UTF-8. So if the content from the link is ISO-8859-1 as many websites use, the characters will be displayed wrong as they are forces as UTF-8.

You need to convert the output into UTF-8 or make sure that it already is to display it correctly.
Copy linkTweet thisAlerts:
@akrashdiauthorMar 28.2010 — Thanks,

Do you know any reliable methods for converting ISO-8859-1 to UTF8 or ASCII (HTML Entities)?
Copy linkTweet thisAlerts:
@QuidamMar 28.2010 — utf8_encode()
Copy linkTweet thisAlerts:
@NogDogMar 28.2010 — Also note that if your web server is sending a HTTP header indicating ISO-8859-1 (or some other character set), your browser may ignore the meta tag setting. Therefore you may want to add a header() call before any output:
[code=php]
<?php
header("Content-Type: text/html; charset=UTF-8");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Title</title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'></head><body>
<?php
echo file_get_contents('http://www.google.com/search?&hl=ur&q=%D8%A7%D9%84%D8%B4%D8%B1%D9%8A%D8%B9%DB%81');
?>
</body></html>
[/code]
×

Success!

Help @akrashdi 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.4,
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,
)...