6

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 ?

4
  • 1
    What is "without polish letters"? Do they come out as mojibake, or are they completely ignored? Commented Mar 14, 2013 at 9:58
  • cosśźć => cos (cut the string) Commented Mar 14, 2013 at 9:59
  • but the problem is when I run it from browser - is "cosśźć" user input? if so, sounds like your html page is missing a UTF-8 metatag, and the string your script receives is not what you think. Commented Mar 14, 2013 at 10:02
  • No, input is in UTF but I tried run this without input just exec("sendsms 888888888 cosśźćłó"); Commented Mar 14, 2013 at 10:19

1 Answer 1

9

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śźćłó"); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.