The best way I have tried before is to use urlencode()
. Keep in mind, don't use it for the whole url; instead, use it only for the needed parts. For example, a request that has two 'text-fa' and 'text-en' fields and they contain a Persian and an English text, respectively, you might only need to encode the Persian text, not the English one.
However, there are better ways if the range of characters have to be encoded is more limited. One of these ways is using CURLOPT_ENCODING
, by passing it to curl_setopt()
:
curl_setopt($ch, CURLOPT_ENCODING, "");