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: 910.813 // 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); } |
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.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: Anonymous and Shawn Houser.
<your name here>