Use PHP functions in JavaScript

JavaScript sql_regcase

Make regular expression for case insensitive match

1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
25
function sql_regcase (str) {
    // Make regular expression for case insensitive match  
    // 
    // version: 1001.2911
    // discuss at: http://phpjs.org/functions/sql_regcase    // +   original by: Brett Zamir (http://brett-zamir.me)
    // -    depends on: setlocale
    // *     example 1: sql_regcase('Foo - bar.');
    // *     returns 1: '[Ff][Oo][Oo] - [Bb][Aa][Rr].'
    this.setlocale('LC_ALL', 0);    var i=0, upper = '', lower='', pos=0, retStr='';
 
    upper = this.php_js.locales[this.php_js.localeCategories.LC_CTYPE].LC_CTYPE.upper;
    lower = this.php_js.locales[this.php_js.localeCategories.LC_CTYPE].LC_CTYPE.lower;
     for (i=0; i < str.length; i++) {
        if (((pos = upper.indexOf(str.charAt(i))) !== -1) || ((pos = lower.indexOf(str.charAt(i))) !== -1)) {
            retStr += '['+upper.charAt(pos)+lower.charAt(pos)+']';
        }
        else {            retStr += str.charAt(i);
        }
    }
    return retStr;
}
external links: original PHP docs | raw js source

Examples

Running

1
sql_regcase('Foo - bar.');

Should return

1
'[Ff][Oo][Oo] - [Bb][Aa][Rr].'

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 sql_regcase 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

More functions

In this category

preg_grep
preg_quote
» sql_regcase

Support us

spread the word:


Use any PHP function in JavaScript


These kind folks have already donated: Anonymous and Shawn Houser.
<your name here>

Click here to lend your support to: phpjs and make a donation at www.pledgie.com !