/    Sign up×
Community /Pin to ProfileBookmark

cURL foreign characters problem

Hello! I have a question regarding the cURL library for PHP. I am trying to use it to fetch a web page. Unfortunately, this page was written poorly, and displays the special characters (such as &#225? directly in the source file (it doesn’t use the html escape codes). When I try to load and echo this, all of the foreign characters are displayed as �. I tried the method suggested on [url]http://us3.php.net/manual/en/function.curl-setopt.php[/url] but it didn’t seem to work for me. Does anyone know how I can properly escape these within my PHP script so they will end up displaying properly?

Thank you.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@svidgenSep 16.2008 — You might get some luck running the data returned from cURL through htmlentities(): http://us2.php.net/manual/en/function.htmlentities.php.

I haven't had a chance to try the function myself. So, if it works for you, please let us know.
Copy linkTweet thisAlerts:
@gnu1983authorSep 16.2008 — Thanks for the help. I got it working.

Running htmlentities on it made it escape all of the html, so the source of the html page I was going to display was shown instead of the actual page. After running it through htmlentities, I immediately ran it through html_entity_decode, with UTF-8 encoding. The resulting code looked like:
[code=php]$page = html_entity_decode(htmlentities(curl_exec($url)), ENT_COMPAT, 'UTF-8');
[/code]

Thanks a lot!
×

Success!

Help @gnu1983 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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