Use PHP functions in JavaScript

JavaScript strcoll

Compares two strings using the current locale

1
2
3
4
56
7
8
9
1011
12
13
14
15
function strcoll (str1, str2) {
    // Compares two strings using the current locale  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/strcoll    // +   original by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // -    depends on: setlocale
    // *     example 1: strcoll('a', 'b');
    // *     returns 1: -1    this.setlocale('LC_ALL', 0); // ensure setup of localization variables takes place
    var cmp = this.php_js.locales[this.php_js.localeCategories.LC_COLLATE].LC_COLLATE;
    // return str1.localeCompare(str2); // We don't use this as it doesn't allow us to control it via setlocale()
    return cmp(str1, str2);
}
external links: original PHP docs | raw js source

Examples

Running

1
strcoll('a', 'b');

Should return

1
-1

Dependencies

In order to use this function, you also need:

Open syntax issues

php.js uses JsLint to help us keep our code consistent and prevent some common bugs.

Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.


Authors

Thanks to the following developers, you get to have strcoll goodness in JavaScript.

Comments

Add Comment
Use:
[CODE]
your_stuff('here');
[/CODE]
for proper code formatting
By submitting code here you are allowing us to use it in php.js hence dual licensing it under the MIT and GPL licenses

No comments yet. Be the first!


Contribute a New function