PHP and special chars. How to?

2 views
Skip to first unread message

Carlo

unread,
Mar 20, 2009, 4:29:46 AM3/20/09
to Twitter Development Talk
Hi. I'm new in flickr api, and i'm still looking around to better
understand how it works.

I'm working with PHP and I have a problem with special chars. I send
to twitter a request like this:

$url = "http://twitter.com/statuses/friends_timeline.xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
$result = curl_exec($ch);
curl_close($ch);

Then I handle the result with something like this:

$xml = simplexml_load_string($result);
foreach ($xml->status as $status) {
$image = $status->user->profile_image_url;
$name = $status->user->screen_name;
$icon = '<img src="' . $image . '" title="' . $name . '"
align="middle" />';
$text = $status->text;
echo "<p>" . $icon . " " . $text . "</p>\n";
}

The problem is in special chars. If I wrote (in italian) the following
text:

"Il mio nome è Carlo"

the API returns something like:

"Il mio nome À Carlo"

I used PHP function htmlspecialchars(), but with no success.

Can anybody help me?

Thanks a lot
Carlo

Cameron Kaiser

unread,
Mar 20, 2009, 8:54:52 AM3/20/09
to twitter-deve...@googlegroups.com
> The problem is in special chars. If I wrote (in italian) the following
> text:
>
> "Il mio nome _ Carlo"

>
> the API returns something like:
>
> "Il mio nome _ Carlo"

>
> I used PHP function htmlspecialchars(), but with no success.

Your problem here is UTF-8 (which of course Elm just ate), not HTML special
characters. Going into PHP multibyte support is not germaine for this list,
but look at the utf8_{encode,decode} functions, iconv and mbstring. This is a
nice cheatsheet on mbstring:

http://www.nicknettleton.com/zine/php/php-utf-8-cheatsheet

--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com
-- When relatives are outlawed, only outlaws will have inlaws. ----------------

Message has been deleted

Carlo

unread,
Mar 20, 2009, 3:46:04 PM3/20/09
to Twitter Development Talk
Hi, Cameron.

I used

$text = utf8_decode($status->text);

and it works well.

Thanks a lot



On 20 Mar, 13:54, Cameron Kaiser <spec...@floodgap.com> wrote:
> > The problem is in special chars. If I wrote (in italian) the following
> > text:
>
> > "Il mio nome _ Carlo"
>
> > the API returns something like:
>
> > "Il mio nome _ Carlo"
>
> > I used PHP function htmlspecialchars(), but with no success.
>
> Your problem here is UTF-8 (which of course Elm just ate), not HTML special
> characters. Going into PHP multibyte support is not germaine for this list,
> but look at the utf8_{encode,decode} functions, iconv and mbstring. This is a
> nice cheatsheet on mbstring:
>
>        http://www.nicknettleton.com/zine/php/php-utf-8-cheatsheet
>
> --
> ------------------------------------ personal:http://www.cameronkaiser.com/--
>   Cameron Kaiser * Floodgap Systems *www.floodgap.com* ckai...@floodgap.com
Reply all
Reply to author
Forward
0 new messages