-4

Why does

<?php 

echo "HELLO WORLD 1"; // shows
error_reporting(E_ALL);
echo "HELLO WORLD 2"; // shows
print_r(mb_list_encodings()); // does not show
echo "HELLO WORLD 3"; // does not show
$result = mb_convert_encoding("apple", 'UTF-8');
echo "HELLO WORLD 4"; // does not show;
echo $result; // does not show;

// no error what so ever displayed.

?>

fail? What can make this function fail?

I have a PHP web page that runs code and halts at this line, and returns HTTP 500 error.

But I don't know why it fails. Any suggestion for where to check?

Update: Error Log shows

PHP Fatal error:  Call to undefined function mb_convert_encoding()
Jake
  • 11,273
  • 21
  • 90
  • 147
  • Check your error log! It will contain a more verbose error description than "500". – deceze Sep 01 '15 at 06:50
  • Turn on error reporting/logging – GordonM Sep 01 '15 at 06:51
  • Where is your php page??? – Saty Sep 01 '15 at 06:51
  • http 500 is a internal redirection fail, it has not relationship to mb_convert_encoding function – Andrew Sep 01 '15 at 06:54
  • Why vote to close? @Andrew ok, then ignore the http 500. Question is why mb_convert_encoding fail. – Jake Sep 01 '15 at 06:58
  • First of all make sure that this line in the cause of the failure. If you do that, use `mb_list_encodings()` to check your system supported encodings. Then try to specify the `from_encoding` part of the `mb_convert_encoding` call. See php's documentation on [mb_convert_encoding](http://php.net/manual/en/function.mb-convert-encoding.php) for more details. If you don't specify the `from_encoding` part then php uses your system's dafault encoding. I guess if the encoding isn't supported it may cause some kind of failure. – Master_ex Sep 01 '15 at 06:58
  • @Andrew 500 is a "user friendly" response inserted by the web server to cover the actual error message. It has nothing to do with redirection (or you need to clarify what you mean by that term). The error that caused the 500 to be inserted may very well be this line of code, it's as plausible as anything else. Having said that, I couldn't think of a scenario where `mb_convert_encoding` would fail fatally, and again: **your error log will have details!** – deceze Sep 01 '15 at 07:01
  • @deceze thanks for clarifying it. I actually only know http 500 is something to due with the internal, not like 404 which page are not found by request. but my point is that there is no circumstance that it will related to mb_* functionality.. – Andrew Sep 01 '15 at 07:06
  • Thanks for all the comments so far, I have updated the question to be more specific, showing the entire php file code. – Jake Sep 01 '15 at 07:09
  • Is there any actual problem with you having a look at your **error logs**?! – deceze Sep 01 '15 at 07:10
  • if `mb_list_encodings()` doesnt show I think it lies in a bigger problem? maybe error while installation or php version < 5 ? I hope someone can point you the right direction :) – Andrew Sep 01 '15 at 07:10
  • @Andrew The web server shunts an incoming request to PHP. If the PHP program suddenly dies, that's an *internal error* and the web server responds with a 500 page. It means "something bad happened here on the server, sorry for that." It *may very well* be a problem with the `mb_convert_encoding` function, who knows? Oh, wait... **the error log will know!** – deceze Sep 01 '15 at 07:12
  • @deceze I swear I checked the error log before and didn't find anything until now I moved the code block to a single file then I can see it logs the undefined function call error. Why is it undefined? Any extension need to be installed? – Jake Sep 01 '15 at 07:15
  • i have found a similar question in SO, it might be helpful http://stackoverflow.com/questions/8266396/mb-convert-encoding-undefined-function-while-mbstring-is-enabled – Andrew Sep 01 '15 at 07:16
  • @Jake thats what I thought too, may I know how you install your php so I can avoid in the future? thanks :) – Andrew Sep 01 '15 at 07:19

1 Answers1

3

PHP Fatal error: Call to undefined function mb_convert_encoding()

That means mb_convert_encoding is not installed, because the MB extension is not installed on your version of PHP. How to install it depends on how you installed PHP. Mostly likely your operating system has a package manager (apt-get or such) that will allow you to install it quickly. Otherwise, see the manual.

deceze
  • 510,633
  • 85
  • 743
  • 889