How to tweet special characters without compromising my server?

php

#1

Hi,
I’ve built an app in PHP/MySQL and I have a problem using statuses/update.json with special characters.

It’s actually a two-fold issue. Firstly, I need to find a way to allow users to post exclamation marks and double-quotes. So far I’m running tests with something like this:

$tweet = preg_replace("/[^a-zA-Z0-9_.;:\/@? -]/", '', $tweetUncl);

Yes, it protects my database but I can’t tell people not to use exclamation marks :slight_smile:

Secondly, how do I enable emojis? If I send a tweet like this:
This is my emoji: & #128520;

That’s exactly how it is posted on Twitter. I’ve tried all possible encodings, including unicode, utf-8 etc etc… How do I encode them?

Any help would be greatly appreciated!
Thanks.


#2

UTF-8 is utf8mb4_unicode_ci in mySQL. Setting the collation at the table level is not enough. There are INI settings required as well.

Talk to your service provider. Our tweets go out with emojis and in (last count) 7 languages