Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:33:15+00:00 2026-05-26T13:33:15+00:00

I was trying range(); function with non-English language. It is not working. $i =0

  • 0

I was trying range(); function with non-English language. It is not working.

$i =0
foreach(range('क', 'म') as $ab) {

    ++$i;

    $alphabets[$ab] = $i;

}

Output: à =1

It was Hindi (India) alphabets. It is only iterating only once (Output shows).

For this, I am not getting what to do!

So, if possible, please tell me what to do for this and what should I do first before thinking of working with non-English text with any PHP functions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:33:16+00:00Added an answer on May 26, 2026 at 1:33 pm

    Short answer: it’s not possible to use range like that.

    Explanation

    You are passing the string ‘क’ as the start of the range and ‘म’ as the end. You are getting only one character back, and that character is à.

    You are getting back à because your source file is encoded (saved) in UTF-8. One can tell this by the fact that à is code point U+00E0, while 0xE0 is also the first byte of the UTF-8 encoded form of ‘क’ (which is 0xE0 0xA4 0x95). Sadly, PHP has no notion of encodings so it just takes the first byte it sees in the string and uses that as the “start” character.

    You are getting back only à because the UTF-8 encoded form of ‘म’ also starts with 0xE0 (so PHP also thinks that the “end character” is 0xE0 or à).

    Solution

    You can write range as a for loop yourself, as long as there is some function that returns the Unicode code point of an UTF-8 character (and one that does the reverse). So I googled and found these here:

    // Returns the UTF-8 character with code point $intval
    function unichr($intval) {
        return mb_convert_encoding(pack('n', $intval), 'UTF-8', 'UTF-16BE');
    }
    
    // Returns the code point for a UTF-8 character
    function uniord($u) {
        $k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8');
        $k1 = ord(substr($k, 0, 1));
        $k2 = ord(substr($k, 1, 1));
        return $k2 * 256 + $k1;
    }
    

    With the above, you can now write:

    for($char = uniord('क'); $char <= uniord('म'); ++$char) {
        $alphabet[] = unichr($char);
    }
    
    print_r($alphabet);
    

    See it in action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a function : Input: Source range, Source value, output range,
Cells(4, x) = Application.WorksheetFunction.COUNTA(Workbooks(DB_Report.xls).Sheets(x).Range(A:A)) I am trying to get the above function to work.
I'm trying to use assert to check if another function is working correctly. In
I'm trying to create a function so that =processCells(A1:A10) will take the range of
I am trying to iterate through the range(750, 765) and add the non-sequential numbers
I am trying to this function: def sleep(sec): for i in range(sec): print(., end=
i'm trying to build a function that will tell me the range of a
I am trying to write a vba function that takes a range as an
I'm trying to select the used range. I get the worksheet's UsedRange, then I
I am trying to use the range property of the jQuery slider so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.