0

I was trying to send Farsi message from server to telegram and I got this error:

PHP Warning: file_get_contents(https://api.telegram.org/botTOKEN/sendmessage?parse_mode=html&chat_id=CHAT_ID&text=%D8%A7%DB%8C%D9%85%D9%86%D8%AF+%D9%88%D8%A8%E2%80%8C%D8%B3%D8%A7%DB%8C%D8%AA%DB%8C+%D8%0A+%0A%3Ca+href%3D%22https%3A%2F%2FURL%22%3E%D9%88%D8%A8%E2%80%8C%D8%B3%D8%A7%DB%8C%D8%AA+%D8%A7%DB%8C%D9%85%D9%86%D8%AF+-+%D8%A7%DB%8C%D8%AF%D9%87+%D8%A8%D8%B2%D9%86%21%3C%2Fa%3E%0A%40URL): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

Can anyone help me? I guess the problem is with Farsi language and URL encoding but I don't know how to solve it.

1 Answers1

2

Your text must be properly URL encoded. You can do this with urlencode($text).

For your URL to work you have to remove the %D8 right after the occurence of the second + sign.

%D8%A7%DB%8C%D9%85%D9%86%D8%AF+%D9%88%D8%A8%E2%80%8C%D8%B3%D8%A7%DB%8C%D8%AA%DB%8C+%0A+%0A%3Ca+href%3D%22https%3A%2F%2FURL%22%3E%D9%88%D8%A8%E2%80%8C%D8%B3%D8%A7%DB%8C%D8%AA+%D8%A7%DB%8C%D9%85%D9%86%D8%AF+-+%D8%A7%DB%8C%D8%AF%D9%87+%D8%A8%D8%B2%D9%86%21%3C%2Fa%3E%0A%40URL
newsha
  • 1,288
  • 1
  • 10
  • 13