I have been searching for some time for what I am trying to accomplish, and I am not an expert in this emoji 'stuff' and I need some help
I have an application which has multiple SMS service providers attached (2 of them at the moment), which sends SMS messages to (inbound), and we send SMS (outbound) all via API.
When an SMS message is received (from either provider), our platform sees the incoming text (with emojis) as:
"hello \ud83e\udd2a"
I have already changed my database to store the emojis, and I changed my charset in the PHP application to display them correctly in HTML, including the email forward, so I am all good there
The issue I am running into is that 1 of the providers (when sending) will accept this as a vaild emoji:
"hello to you \ud83e\udd2a"
But the other will not. The second provider needs (i think) HTML Dec format, so when I sent to them, it needs to look like this:
"hello to you 😀 ;"
I have 2 separate php functions to send to each provider, so I can do any conversion code from the front-app I need to before it sends it to the provider.
My front-end is using a jQuery emoji picker, so the PHP form post sends "hello to you \ud83e\udd2a" to the php function that calls the API.
Any insight you can give will be greatly appreciated!
thanks in advance.
$utf32 = mb_convert_encoding($message['text'], 'UTF-32', 'UTF-8' );
$hex4 = bin2hex($utf32);
$dec = hexdec($hex4);
$emoji_replaced = "&#$dec;";
echo "&#$dec;";
this was giving me a dec value of the whole string
As a start, when the JSON document is decoded the \ud83e\udd2a will be decoded to the standard 🤪 emoji. These escapes are part of the JSON spec.
As for the provider that "doesn't support" emojis, they likely using a text encoding other than UTF-8 that will fail to display any "special" character or non-english text, not just emojis. This is further evidenced by the fact that they can still render the emoji when you send it as an HTML entity.
While you can use the below code to convert emojis to HTML entity sequences, you should also be checking that other providers docs as to the encoding they use, and converting the messages appropriately. That said, non-UTF-8 encodings simply do not have emojis at all, so you may still want to convert to entities first.
As their name implies, HTML entities will only work when viewed as part of an HTML document. YMMV.
<?php
function emoji_to_entity($emoji) {
return sprintf(
'&#%s;',
unpack(
'Ntgt',
mb_convert_encoding($emoji, 'UTF-32', 'UTF-8')
)['tgt']
);
}
// PHP>=8.2 supports the Extended_Pictographic property
//$emoji_regex = '/\p{Extended_Pictographic}/u';
// PHP<8.2 needs to use a monstrous regex like this
// culled from: https://raw.githubusercontent.com/PCRE2Project/pcre2/master/maint/Unicode.tables/emoji-data.txt
$emoji_regex = '/[\x{23}-\x{23}\x{2a}-\x{2a}\x{30}-\x{39}\x{a9}-\x{a9}\x{ae}-\x{ae}\x{200d}-\x{200d}\x{203c}-\x{203c}\x{2049}-\x{2049}\x{20e3}-\x{20e3}\x{2122}-\x{2122}\x{2139}-\x{2139}\x{2194}-\x{2199}\x{21a9}-\x{21aa}\x{231a}-\x{231b}\x{2328}-\x{2328}\x{2388}-\x{2388}\x{23cf}-\x{23cf}\x{23e9}-\x{23f3}\x{23f8}-\x{23fa}\x{24c2}-\x{24c2}\x{25aa}-\x{25ab}\x{25b6}-\x{25b6}\x{25c0}-\x{25c0}\x{25fb}-\x{25fe}\x{2600}-\x{2605}\x{2607}-\x{2612}\x{2614}-\x{2685}\x{2690}-\x{2705}\x{2708}-\x{2712}\x{2714}-\x{2714}\x{2716}-\x{2716}\x{271d}-\x{271d}\x{2721}-\x{2721}\x{2728}-\x{2728}\x{2733}-\x{2734}\x{2744}-\x{2744}\x{2747}-\x{2747}\x{274c}-\x{274c}\x{274e}-\x{274e}\x{2753}-\x{2755}\x{2757}-\x{2757}\x{2763}-\x{2767}\x{2795}-\x{2797}\x{27a1}-\x{27a1}\x{27b0}-\x{27b0}\x{27bf}-\x{27bf}\x{2934}-\x{2935}\x{2b05}-\x{2b07}\x{2b1b}-\x{2b1c}\x{2b50}-\x{2b50}\x{2b55}-\x{2b55}\x{3030}-\x{3030}\x{303d}-\x{303d}\x{3297}-\x{3297}\x{3299}-\x{3299}\x{fe0f}-\x{fe0f}\x{1f000}-\x{1f0ff}\x{1f10d}-\x{1f10f}\x{1f12f}-\x{1f12f}\x{1f16c}-\x{1f171}\x{1f17e}-\x{1f17f}\x{1f18e}-\x{1f18e}\x{1f191}-\x{1f19a}\x{1f1ad}-\x{1f1ff}\x{1f201}-\x{1f20f}\x{1f21a}-\x{1f21a}\x{1f22f}-\x{1f22f}\x{1f232}-\x{1f23a}\x{1f23c}-\x{1f23f}\x{1f249}-\x{1f53d}\x{1f546}-\x{1f64f}\x{1f680}-\x{1f6ff}\x{1f774}-\x{1f77f}\x{1f7d5}-\x{1f7ff}\x{1f80c}-\x{1f80f}\x{1f848}-\x{1f84f}\x{1f85a}-\x{1f85f}\x{1f888}-\x{1f88f}\x{1f8ae}-\x{1f8ff}\x{1f90c}-\x{1f93a}\x{1f93c}-\x{1f945}\x{1f947}-\x{1faff}\x{1fc00}-\x{1fffd}\x{e0020}-\x{e007f}]/u';
$input = json_decode('"hello to you \ud83e\udd2a"');
var_dump(
$input,
preg_replace_callback(
$emoji_regex,
function($a) { return emoji_to_entity($a[0]); },
$input
)
);
Output:
string(17) "hello to you 🤪"
string(22) "hello to you 🤪"
And outside of a code block: string(22) "hello to you 🤪"
Related
I am feeling a bit awkward, because I am generating a mail-body with PHP without escaping the variables. In HTML I am using htmlspecialchars() or similar functions, for command lines escapeshellarg(), but for mails? For example something like this:
<?php
$usercontent = $_GET['usercontent'];
mail("dummy#nowhere.tld", "My Subject", "My body with $usercontent included");
?>
What could a possible attacker do with a script like the one above and how could I protect against such an attack? Or is PHP mail() save and why?
Update
Please refer to the example:
Only the body is affected (No Headers!)
Content-Type is text/plain
Some proof to the answer would be nice
MTA is a postfix sendmail with "/usr/sbin/sendmail -t -i"
The basic e-mail message body is plain text. If you want a different type like HTML or a multipart message, you need to use the MIME extension and specify the type accordingly using Content-Type (e.g. text/html for HTML or multipart/… for a multipart message).
So from the security perspective, there is no way to inject anything harmful (at least not as per specification). Even non-ASCII characters should be handled correctly despite the lacking declaration of the used character encoding.
However, there still may be some flaws in e-mail clients which can be exploited this way. But I doubt that.
Good question. I don't believe you need to escape the body text, but I do know it's possible to add headers to a mail (like a BCC to thousands of addresses) if you allow the user to input a from address. So if you put variables in that, definitely check for newlines (\n and \r) to make sure no additional headers are added.
Think of the body of the email this way: "Mission top secret destination unknown." We may not know what kind of client will read the message, but we can guess that we do not want live, user supplied, unescaped HTML to show up in it. Since many clients read mail in HTML, the best thing to do would be to htmlentities() the user supplied e-mail body.
A method from my escaper class.
<?php
class escaper
{
public function superHtmlEntities($string)
{
return htmlentities($string, ENT_QUOTES | ENT_HTML5, 'UTF-8', true);
}
}
?>
========================================
At minimum, consider something like this and more as you do your research.
<?php
$esc = new Escaper();
$usercontent = $_GET['usercontent'];
mail("dummy#nowhere.tld", "My Subject", $esc->superHtmlEntities("My body with $usercontent included"));
?>
It is not secured against XSS atack because if your mail contains HTML someone can inject it into mail.
The good behaviour is to check and valid data which you expect to have. If I were you I would escape this string. It costs almoust nothing and you don't have to worry about consequences of not using it.
I have a PHP function that internally builds an object graph using among other things one string parameter, then uses json_encode() to create a JSON string and then post the JSON string to a remote web service.
Like this:
function send($text)
{
$payload = array(
'text' => $text
// Set additional properties here ...
);
$payload_json = json_encode($payload);
// Post $payload_json to remote service with Curl ...
}
From the manual of json_encode (http://php.net/manual/en/function.json-encode.php)
All string data must be UTF-8 encoded.
I see a couple of options:
Attempt to validate that $text is in fact UTF-8 and throw an exception if it is not
Attempt to detect the encoding in $text and convert it to UTF-8 if necessary
Return false when $text is not UTF-8
Communicate with my API users in documentation that $text must be UTF-8
Check for error with json_last_error() and throw an exception if an error was encountered
What is the best practice?
You should always communicate to the users of the API what you're expecting.
If you expect UTF-8 encoded text, say so in your documentation.
Once it's in there, you should return a descriptive error such as "Invalid Encoding, for more information read the documentation: link" where link goes to the relevant page for the call that failed
This way, you're not responsible anymore, and the developers that use your API will know what is going wrong, and you don't have to worry about it in your API.
You're the developer, it's your API, and your API has it's own rules, if people want to use it, they need to follow the rules you set.
I have a function which is meant to move a mail from one folder to another on a gmail account.
The function is fully functional when it comes to moving the mail. Tho my problem appears when
working with utf-8 encoded mailboxes. I decode the IMAP folder list response
but the dump of both values gives different results.
// Getting the folders
$folders = imap_list(CONNECTION, MAILBOX, PATTERN);
// After a foreach, stripping slash, prefix and such
// $folder is the raw mailbox name from the IMAP list
$mailbox = utf8_encode(imap_utf7_decode($folder)); // = string(12) "Tæstbåks"
// The entered search from the client
$search_for = "Tæstbåks"; // = string(10) "Tæstbåks"
if($search_for == $mailbox)
print "Yeah!";
else
print "Noo!";
I do not know why those two strings do not match, that is my problem.
PHP's function imap_utf7_decode($folder) is documented to return a string in ISO-8859-1 encoding. Given that IMAP's modified UTF-7 scheme can encode the whole range of Unicode (which means "a lot") and that ISO-8859-1 can only represent 256 individual characters, you cannot possibly use that function in this context. I would go as far as to suggest that the PHP developer who decided to offer such a useless function was not in his best shape the day he designed it.
It looks like the mbstring extension can do what you really want to do here -- use something like $mailbox = mb_convert_encoding($folder, "UTF-8", "UTF7-IMAP"), as suggested in the comments below the PHP's docs.
How to convert something like this
\xe6\xa6\x82\xe8\xa6\x81\n\xe3\x83\xbb\xe3\x82\xb0\xe3\x83\xaa\xe3\x83\xbc\xe3\x81\xae\xe3\x82\xa8\xe3\x83\xb3\xe3\x82\xb8\xe3\x83\x8b\xe3\x82\xa2\xe3\x81\xab\xe5\xbf\x9c\xe5\x8b\x9f\xe3\x81\x97\xe3\x81\xa6\xe3\x81\xbf\xe3\x81\x9f\xe3\x81\x84\xe3\x81\x8c\xe3\x80\x81\xe5\xbf\x9c\xe5\x8b\x9f\xe5\x89\x8d\xe3\x81\xab\xe8\x87\xaa\xe5\x88\x86\xe3\x81\xae\xe5\xae\x9f\xe5\x8a\x9b\xe3\x82\x92\xe8\xa9\xa6\xe3\x81\x97\xe3\x81\xa6\xe3\x81\xbf\xe3\x81\x9f\xe3\x81\x84\xe3\x80\x82\n\xe3\x83\xbb\xe5\x9c\xb0\xe6\x96\xb9\xe3\x81\xab\xe4\xbd\x8f\xe3\x82\x93\xe3\x81\xa7\xe3\x81\x84\xe3\x82\x8b\xe3\x81\xae\xe3\x81\xa7\xe9\x9d\xa2\xe6\x8e\xa5\xe5\x9b\x9e\xe6\x95\xb0\xe3\x81\x8c\xe5\xb0\x91\xe3\x81\xaa\xe3\x81\x84\xe6\x96\xb9\xe3\x81\x8c\xe3\x81\x82\xe3\x82\x8a\xe3\x81\x8c\xe3\x81\x9f\xe3\x81\x84\xe3\x80\x82\n\xe3\x83\xbb\xe9\x9d\xa2\xe6\x8e\xa5\xe3\x81\xaf\xe8\x8b\xa6\xe6\x89\x8b\xe3\x81\xa0\xe3\x81\x8c\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\x9f\xe3\x83\xb3\xe3\x82\xb0\xe3\x81\xab\xe3\x81\xaf\xe8\x87\xaa\xe4\xbf\xa1\xe3\x81\x8c\xe3\x81\x82\xe3\x82\x8b\xe3\x80\x82\xe3\x81\xaf\xe3\x80\x81\xe3\x81\x93\xe3\x81\xae\xe3\x82\x88\xe3\x81\x86\xe3\x81\xaa\xe6\x96\xb9\xe3\x80\x85\xe3\x81\xae\xe3\x81\x94\xe8\xa6\x81\xe6\x9c\x9b\xe3\x81\xab\xe3\x81\x8a\xe5\xbf\x9c\xe3\x81\x88\xe3\x81\x99\xe3\x82\x8b\xe3\x81\x9f\xe3\x82\x81\xe3\x81\xab\xe4\xbd\x9c\xe3\x82\x89\xe3\x82\x8c\xe3\x81\x9f\xe6\x96\xb0\xe3\x81\x97\xe3\x81\x84\xe6\x8e\xa1\xe7\x94\xa8\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\xa0\xe3\x81\xa7\xe3\x81\x99\xe3\x80\x82\n\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\x9f\xe3\x83\xb3\xe3\x82\xb0\xe3\x82\xb9\xe3\x82\xad\xe3\x83\xab\xe3\x82\x92\xe8\xa9\x95\xe4\xbe\xa1\xe3\x81\x99\xe3\x82\x8b\xef\xbc\x91\xe6\xac\xa1\xe9\x9d\xa2\xe6\x8e\xa5\xe3\x82\x92\xe3\x83\x91\xe3\x82\xb9\xe3\x81\xa7\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x99\xe3\x81\xae\xe3\x81\xa7\xe5\x8a\xb9\xe7\x8e\x87\xe7\x9a\x84\xe3\x81\xaa\xe8\xbb\xa2\xe8\x81\xb7\xe6\xb4\xbb\xe5\x8b\x95\xe3\x82\x92\xe8\xa1\x8c\xe3\x81\xa3\xe3\x81\xa6\xe9\xa0\x82\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\n\xe3\x82\x82\xe3\x81\xa1\xe3\x82\x8d\xe3\x82\x93\xe5\xad\xa6\xe7\x94\x9f\xe3\x81\xae\xe7\x9a\x86\xe3\x81\x95\xe3\x82\x93\xe3\x81\xae\xe3\x83\x81\xe3\x83\xa3\xe3\x83\xac\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x82\xe3\x81\x8a\xe5\xbe\x85\xe3\x81\xa1\xe3\x81\x97\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82
which i received in HTTP POST to show them properly on HTML web page.
I have no idea what I am looking at but i think i can be converted to something which look in this ☺ format.
How can i do this in PHP
If you send the appropriate character set encoding with your HTTP response, you don't have to do anything to the data, the browser should properly decode it as Japanese text.
Example:
<?php
header('Content-Type: text/html; charset=UTF-8');
$var = "\xe6\xa6\x82\xe8\xa6\x81\n\xe3\x83\xbb\xe3\x82\xb0\xe3\x83\xaa\xe3\x83\xbc\xe3\x81\xae\xe3\x82\xa8\xe3\x83\xb3\xe3\x82\xb8\xe3\x83\x8b\xe3\x82\xa2\xe3\x81\xab\xe5\xbf\x9c\xe5\x8b\x9f\xe3\x81\x97\xe3\x81\xa6\xe3\x81\xbf\xe3\x81\x9f\xe3\x81\x84\xe3\x81\x8c\xe3\x80\x81\xe5\xbf\x9c\xe5\x8b\x9f\xe5\x89\x8d\xe3\x81\xab\xe8\x87\xaa\xe5\x88\x86\xe3\x81\xae\xe5\xae\x9f\xe5\x8a\x9b\xe3\x82\x92\xe8\xa9\xa6\xe3\x81\x97\xe3\x81\xa6\xe3\x81\xbf\xe3\x81\x9f\xe3\x81\x84\xe3\x80\x82\n\xe3\x83\xbb\xe5\x9c\xb0\xe6\x96\xb9\xe3\x81\xab\xe4\xbd\x8f\xe3\x82\x93\xe3\x81\xa7\xe3\x81\x84\xe3\x82\x8b\xe3\x81\xae\xe3\x81\xa7\xe9\x9d\xa2\xe6\x8e\xa5\xe5\x9b\x9e\xe6\x95\xb0\xe3\x81\x8c\xe5\xb0\x91\xe3\x81\xaa\xe3\x81\x84\xe6\x96\xb9\xe3\x81\x8c\xe3\x81\x82\xe3\x82\x8a\xe3\x81\x8c\xe3\x81\x9f\xe3\x81\x84\xe3\x80\x82\n\xe3\x83\xbb\xe9\x9d\xa2\xe6\x8e\xa5\xe3\x81\xaf\xe8\x8b\xa6\xe6\x89\x8b\xe3\x81\xa0\xe3\x81\x8c\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\x9f\xe3\x83\xb3\xe3\x82\xb0\xe3\x81\xab\xe3\x81\xaf\xe8\x87\xaa\xe4\xbf\xa1\xe3\x81\x8c\xe3\x81\x82\xe3\x82\x8b\xe3\x80\x82\xe3\x81\xaf\xe3\x80\x81\xe3\x81\x93\xe3\x81\xae\xe3\x82\x88\xe3\x81\x86\xe3\x81\xaa\xe6\x96\xb9\xe3\x80\x85\xe3\x81\xae\xe3\x81\x94\xe8\xa6\x81\xe6\x9c\x9b\xe3\x81\xab\xe3\x81\x8a\xe5\xbf\x9c\xe3\x81\x88\xe3\x81\x99\xe3\x82\x8b\xe3\x81\x9f\xe3\x82\x81\xe3\x81\xab\xe4\xbd\x9c\xe3\x82\x89\xe3\x82\x8c\xe3\x81\x9f\xe6\x96\xb0\xe3\x81\x97\xe3\x81\x84\xe6\x8e\xa1\xe7\x94\xa8\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\xa0\xe3\x81\xa7\xe3\x81\x99\xe3\x80\x82\n\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\x9f\xe3\x83\xb3\xe3\x82\xb0\xe3\x82\xb9\xe3\x82\xad\xe3\x83\xab\xe3\x82\x92\xe8\xa9\x95\xe4\xbe\xa1\xe3\x81\x99\xe3\x82\x8b\xef\xbc\x91\xe6\xac\xa1\xe9\x9d\xa2\xe6\x8e\xa5\xe3\x82\x92\xe3\x83\x91\xe3\x82\xb9\xe3\x81\xa7\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x99\xe3\x81\xae\xe3\x81\xa7\xe5\x8a\xb9\xe7\x8e\x87\xe7\x9a\x84\xe3\x81\xaa\xe8\xbb\xa2\xe8\x81\xb7\xe6\xb4\xbb\xe5\x8b\x95\xe3\x82\x92\xe8\xa1\x8c\xe3\x81\xa3\xe3\x81\xa6\xe9\xa0\x82\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\n\xe3\x82\x82\xe3\x81\xa1\xe3\x82\x8d\xe3\x82\x93\xe5\xad\xa6\xe7\x94\x9f\xe3\x81\xae\xe7\x9a\x86\xe3\x81\x95\xe3\x82\x93\xe3\x81\xae\xe3\x83\x81\xe3\x83\xa3\xe3\x83\xac\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x82\xe3\x81\x8a\xe5\xbe\x85\xe3\x81\xa1\xe3\x81\x97\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82";
echo $var;
Since we send a header saying that the character encoding is UTF-8, the browser knows to decode it as such. You could also use a meta-tag to specify the charset. If the browser was set to auto-detect the code, neither option is necessary, but you can't rely on that.
It looks like Japan
php > echo "\xe6\xa6\x82\xe8\xa6\x81\n\xe3\x83\xbb\xe3\x82\xb0\xe3\x83\xaa\xe3\x83\xbc\xe3\x81\xae\xe3\x82\xa8\xe3\x83\xb3\xe3\x82\xb8\xe3\x83\x8b\xe3\x82\xa2\xe3\x81\xab\xe5\xbf\x9c\xe5\x8b\x9f\xe3\x81\x97\xe3\x81\xa6\xe3\x81\xbf\xe3\x81\x9f\xe3\x81\x84\xe3\x81\x8c\xe3\x80\x81\xe5\xbf\x9c\xe5\x8b\x9f\xe5\x89\x8d\xe3\x81\xab\xe8\x87\xaa\xe5\x88\x86\xe3\x81\xae\xe5\xae\x9f\xe5\x8a\x9b\xe3\x82\x92\xe8\xa9\xa6\xe3\x81\x97\xe3\x81\xa6\xe3\x81\xbf\xe3\x81\x9f\xe3\x81\x84\xe3\x80\x82\n\xe3\x83\xbb\xe5\x9c\xb0\xe6\x96\xb9\xe3\x81\xab\xe4\xbd\x8f\xe3\x82\x93\xe3\x81\xa7\xe3\x81\x84\xe3\x82\x8b\xe3\x81\xae\xe3\x81\xa7\xe9\x9d\xa2\xe6\x8e\xa5\xe5\x9b\x9e\xe6\x95\xb0\xe3\x81\x8c\xe5\xb0\x91\xe3\x81\xaa\xe3\x81\x84\xe6\x96\xb9\xe3\x81\x8c\xe3\x81\x82\xe3\x82\x8a\xe3\x81\x8c\xe3\x81\x9f\xe3\x81\x84\xe3\x80\x82\n\xe3\x83\xbb\xe9\x9d\xa2\xe6\x8e\xa5\xe3\x81\xaf\xe8\x8b\xa6\xe6\x89\x8b\xe3\x81\xa0\xe3\x81\x8c\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\x9f\xe3\x83\xb3\xe3\x82\xb0\xe3\x81\xab\xe3\x81\xaf\xe8\x87\xaa\xe4\xbf\xa1\xe3\x81\x8c\xe3\x81\x82\xe3\x82\x8b\xe3\x80\x82\xe3\x81\xaf\xe3\x80\x81\xe3\x81\x93\xe3\x81\xae\xe3\x82\x88\xe3\x81\x86\xe3\x81\xaa\xe6\x96\xb9\xe3\x80\x85\xe3\x81\xae\xe3\x81\x94\xe8\xa6\x81\xe6\x9c\x9b\xe3\x81\xab\xe3\x81\x8a\xe5\xbf\x9c\xe3\x81\x88\xe3\x81\x99\xe3\x82\x8b\xe3\x81\x9f\xe3\x82\x81\xe3\x81\xab\xe4\xbd\x9c\xe3\x82\x89\xe3\x82\x8c\xe3\x81\x9f\xe6\x96\xb0\xe3\x81\x97\xe3\x81\x84\xe6\x8e\xa1\xe7\x94\xa8\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\xa0\xe3\x81\xa7\xe3\x81\x99\xe3\x80\x82\n\xe3\x83\x97\xe3\x83\xad\xe3\x82\xb0\xe3\x83\xa9\xe3\x83\x9f\xe3\x83\xb3\xe3\x82\xb0\xe3\x82\xb9\xe3\x82\xad\xe3\x83\xab\xe3\x82\x92\xe8\xa9\x95\xe4\xbe\xa1\xe3\x81\x99\xe3\x82\x8b\xef\xbc\x91\xe6\xac\xa1\xe9\x9d\xa2\xe6\x8e\xa5\xe3\x82\x92\xe3\x83\x91\xe3\x82\xb9\xe3\x81\xa7\xe3\x81\x8d\xe3\x81\xbe\xe3\x81\x99\xe3\x81\xae\xe3\x81\xa7\xe5\x8a\xb9\xe7\x8e\x87\xe7\x9a\x84\xe3\x81\xaa\xe8\xbb\xa2\xe8\x81\xb7\xe6\xb4\xbb\xe5\x8b\x95\xe3\x82\x92\xe8\xa1\x8c\xe3\x81\xa3\xe3\x81\xa6\xe9\xa0\x82\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\n\xe3\x82\x82\xe3\x81\xa1\xe3\x82\x8d\xe3\x82\x93\xe5\xad\xa6\xe7\x94\x9f\xe3\x81\xae\xe7\x9a\x86\xe3\x81\x95\xe3\x82\x93\xe3\x81\xae\xe3\x83\x81\xe3\x83\xa3\xe3\x83\xac\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x82\xe3\x81\x8a\xe5\xbe\x85\xe3\x81\xa1\xe3\x81\x97\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82";
概要
・グリーのエンジニアに応募してみたいが、応募前に自分の実力を試してみたい。
・地方に住んでいるので面接回数が少ない方がありがたい。
・面接は苦手だがプログラミングには自信がある。は、このような方々のご要望にお応えするために作られた新しい採用プログラムです。
プログラミングスキルを評価する1次面接をパスできますので効率的な転職活動を行って頂けます。
もちろん学生の皆さんのチャレンジもお待ちしております。
The google translate
Summary
-But I would like to apply for the engineers of the glee, want to try their strength before application.
The smaller the number of times, because they appreciate the interview live in rural areas.
• The programming is confident but not good interview. Is a new adoption program was created to meet the needs of people like this.
You can Tenshoku efficient activities so you can pass the next one interview to evaluate the programming.
We look forward to challenge of course students
Maybe I'm wrong ;)
I have actually no real clue why you get this as POST, but I assume that
\x82
(and the like) stands for a hexa-decimal number. To convert a whole string (ensure it's that format):
$string = eval('return "' . $thatExactInputAsGiven . '";');
$string does now contain the byte-sequence that this submission represents. However I can not tell you which encoding it is in, but probably this one-line above helps you for testing.
If you fear the eval, mind the error handling:
$string = implode('', array_map(function($v){
$r = sscanf($v, '\x%x', $ord);
if (!$r) throw new Exception('Invalid input.');
return chr($ord);
}, str_split($thatExactInputAsGiven, 4)));
I am trying to use POST in Flash (ActionScript 2), to POST values to PHP mail script.
I tried the PHP mail script with HTML form, and it worked perfectly fine.
But when I POST from flash and input non-English characters, I get "????" in the mail.
I tried utf8_encode($_POST["name"]), but it doesn't help.
Edit:
I also tried utf8_decode($_POST["name"]), it didn't work.
Update: (So you wont have to go through all the comments)
I checked the variables in Flash,
the values are stored correctly.
The HTML page where the Flash is embedded is UTF-8 encoded.
I watched the POST headers with FireBug, the POST itself is already messed up, showing "????" instead of the real value.
The the messed up "????" value, is currently url-encoded by flash, and decoded by PHP, resulting in $_POST["name"] == "???";
I suspect its the sendAndLoad method that creates the mess.
Update:
Here is the flash code:
System.useCodepage = true;
send_btn.onRelease = function() {
my_vars = new LoadVars();
my_vars.email = email_box.text;
my_vars.name = name_box.text;
my_vars.family_box = comment.text;
my_vars.phone = phone_box.text;
if (my_vars.email != "" and my_vars.name != "") {
my_vars.sendAndLoad("http://aram.co.il/ido/sendMail.php", my_vars, "POST");
gotoAndStop(2);
} else {
error_clip.gotoAndPlay(2);
}
my_vars.onLoad = function() {
gotoAndStop(3);
};
};
email_box.onSetFocus = name_box.onSetFocus=message_box.onSetFocus=function () {
if (error_clip._currentframe != 1) {
error_clip.gotoAndPlay(6);
}
};
Flash uses UTF8-encoding for all strings, anyway. If you use LoadVars, transfer as a urlencoded string should also work automatically.
So your problem is most probably in the PHP part of your application. For example, in order for UTF8 to work correctly, all individual PHP files must be saved in UTF8-encoded format, as well.
If just changing the file encoding doesn't work, try parsing $HTTP_RAW_POST_DATA first, check if all the fields have been transferred correctly, then go on and echo your way through until you find the place where the encoding is lost.
Update:
Here is your problem: You use System.useCodePage = true;. This requires you to specifically encode all your data as unicode before sending it. Unless you have any other documents in other encodings, and/or allow your users to upload their own text data with their localized encodings, set System.useCodePage = false;, and your utf8-problem should go away.
If you receive data from flash you need to use utf8_decode and not utf8_encode.
Flash uses UTF8 - as long as you don't tell it to use the local characterset. And you want PHP to decode that to good old ISO-8859-1 which PHP uses internally.
You'd only use utf8_encode when preparing data for flash.