2

I am trying to send emojis via my telegram bot but I can not send it when I take it from an array or a variable.

If I a do this in PHP, it works:

$emoji = "\xF0\x9F\x98\x81";
echo $emoji;

But I want to do something like this:

$emoji = "\xF0\x9F\x98\x81";
$content = array('chat_id' => $id, 'text' => $emoji);
$telegram->sendMessage($content);

Thank you in advance.

UPDATE: It doesn't show anything. I've tried with define and it works, but I need array or variables to do it conditionally.

define(emoji, "\xF0\x9F\x98\x81");
$content = array('chat_id' => $id, 'text' => emoji);
$telegram->sendMessage($content);

I think there is a problem with quotes.

UPDATE2: Problem solved, thanks to these link provided by @CaldwellYSR.

You have to send it this way:

$emoji = "\xE2\x98\x94";
$content = array('chat_id' => $id, 'text' => json_decode('"'.$emoji.'"');
$telegram->sendMessage($content);

Thank you so much.

albertoperojo
  • 55
  • 1
  • 2
  • 5
  • can you `var_dump($telegram->sendMessage($content))` as far as I know using a constant vs a string shouldn't make a difference. I'm trying to get at the expected output vs the actual output. I don't know anything about telegram-bot but the PHP is valid. – CaldwellYSR Nov 09 '16 at 14:01
  • 1
    https://github.com/akalongman/php-telegram-bot/issues/48 Does this link help? – CaldwellYSR Nov 09 '16 at 14:06
  • Yes @CaldwellYSR, this helps me a lote. Solved the issue. – albertoperojo Nov 09 '16 at 17:33

1 Answers1

0

You're trying to sendMessage on the array. You need to access the 'text' key in the array like so:

$telegram->sendMessage($content["text"]);
CaldwellYSR
  • 3,056
  • 5
  • 33
  • 50
  • Thanks for the answer but that's not the problem. You have to pass an array to this function. It is working with some other text. – albertoperojo Nov 08 '16 at 21:36
  • You should probably edit your question with more information then. Based on the code you've showed, the string should show. Maybe show us what your results are? – CaldwellYSR Nov 09 '16 at 03:40