Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php exec encoding

When I execute from console this command "sendsms XXXXXXXXX 'śćźłóśadad'" everything is OK. But when I execute it in php with exec("sendsms XXXXXXXXX 'śćźłóśadad'"); the body of msg is without polish letters. Debian console is in UTF-8, php file is in UTF-8. When I execute this php file from cli everything is OK but the problem is when I run it from browser (the same file). Why ? How to fix it ?

like image 453
mitch Avatar asked Mar 14 '13 09:03

mitch


1 Answers

When you run your script via the CLI interface, the subprocess inherits its parent's environment, which contains the variable LANG, used to pass the encoding of the bytes to the underlying C runtime.

Likely when you execute your program via mod_php, LANG is not set. So you may succeed by configuring it yourself:

<?php
putenv('LANG=en_US.UTF-8');
exec("sendsms 888888888 cosśźćłó"); 
like image 121
Raffaele Avatar answered Sep 23 '22 06:09

Raffaele