1

It seems quite strange that some function is defined when it is called by web browsers, but it becomes undefined in command line mode.

For example,

<?php
echo function_exists('mb_detect_encoding') ? 'yes' : 'no';
?>

When it runs in the browsers, it prints "yes" which means this function is already defined.

But when I run this piece of code in command line, it prints "no"

Why? what settings did I miss in command line mode?

4
  • 3
    php.net/manual/en/mbstring.installation.php Commented Apr 18, 2013 at 14:51
  • Strange? Web browser's don't normally run the command-line version of PHP: they run PHP as web server module or CGI/FastCGI. Commented Apr 18, 2013 at 14:52
  • @MikeB I am pretty sure I have installed mbstring Commented Apr 18, 2013 at 14:58
  • 1
    @Steven You wouldn't be getting undefined function if you had. Commented Apr 18, 2013 at 16:05

4 Answers 4

2

on linux you should check /etc/php5/cli/conf.d to se if it is enabled. Otherwise try copying from another enviroment eg /etc/php5/apache2/conf.d

Sign up to request clarification or add additional context in comments.

Comments

1

This is because of the compile time options your distributions selects. It seems that they have enabled it in the cli interpreter but not in the apache module.

Check the installation instructions of the mbstring extension. If you really need it you'll have to compile php for yourself.

Comments

1

The command php -m lists your active modules (extensions).

To see if it's active, search for mbstring in this list. If it isn't there, it may be:

  • Only enabled in the apache_handler php.ini

or

  • Disabled in the cli php.ini

Add an extension=mbstring.so to your global php.ini to enable it. (If it is built as shared library.)

Comments

0

When calling the Script via CommandLine (CLI) be sure to use the same config File as the Webserver uses when it executes PHP.

from "php --help":

-c | Look for php.ini file in this directory

nowadays the modules, mb_string is one of them, are loaded dynamicly...

2 Comments

Click "edit" to update your answer. (if that was what you wanted to do)
sorry, fairly new to stackoverflow :)

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.