0

I am working on a Laravel project and got an empty string the following code.

<?php
    use Locale;

    $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
    // or $locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
    echo $locale;

The result should be en-US, but returns empty string. I could confirm the request header on my Google Chrome browser v95.

Accept-Language: en-US,en;q=0.9

How can I resolve this issue?

Raphael
  • 517
  • 4
  • 18
  • 1
    Then I guess the header doesn’t contain a parseable locale string. It’s difficult to help without knowing _what_ the value of the header you’re testing with is. – Martin Bean Oct 27 '21 at 17:51
  • @Martin Bean I just confirm there is Accept-Language value via chrome inspection. I guess it might be browse problem. But I can't exam it on older browsers. – Raphael Oct 27 '21 at 17:53
  • `Locale::acceptFromHttp('en-US,en;q=0.9')` returns `en_US` for me. Check that `$_SERVER['HTTP_ACCEPT_LANGUAGE']` contains what you expect. – ceejayoz Oct 27 '21 at 18:14
  • @Devstorm21 I didn’t ask if there _was_ an `Accept-Language` header; I said it’s difficult to help without knowing the _value_ of that header. – Martin Bean Oct 27 '21 at 18:26
  • $_SERVER['HTTP_ACCEPT_LANGUAGE'] is 'en-US,en;q=0.9' – Raphael Oct 27 '21 at 18:27
  • What does your code output if you hard-code the value in, i.e. `echo Locale::acceptFromHttp('en-US,en;q=0.9')`? – ceejayoz Oct 28 '21 at 11:35

1 Answers1

0

I could resolve the error out to edit c:\xampp\php\php.ini. and enable "extension=php_intl.dll".

Raphael
  • 517
  • 4
  • 18