/js/yii/vendors/phpjs/php.js
JavaScript | 7274 lines | 4178 code | 533 blank | 2563 comment | 1166 complexity | f435a70ee00a32b18ecea0911100c6b9 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*
- * More info at: http://phpjs.org
- *
- * This is version: 3.24
- * php.js is copyright 2011 Kevin van Zonneveld.
- *
- * Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld
- * (http://kevin.vanzonneveld.net), Onno Marsman, Theriault, Michael White
- * (http://getsprink.com), Waldo Malqui Silva, Paulo Freitas, Jonas Raoni
- * Soares Silva (http://www.jsfromhell.com), Jack, Philip Peterson, Ates Goral
- * (http://magnetiq.com), Legaev Andrey, Ratheous, Alex, Martijn Wieringa,
- * Nate, lmeyrick (https://sourceforge.net/projects/bcmath-js/), Enrique
- * Gonzalez, Philippe Baumann, Rafał Kukawski (http://blog.kukawski.pl),
- * Webtoolkit.info (http://www.webtoolkit.info/), Ole Vrijenhoek, Ash Searle
- * (http://hexmen.com/blog/), travc, Carlos R. L. Rodrigues
- * (http://www.jsfromhell.com), Jani Hartikainen, stag019, GeekFG
- * (http://geekfg.blogspot.com), WebDevHobo (http://webdevhobo.blogspot.com/),
- * Erkekjetter, pilus, Rafał Kukawski (http://blog.kukawski.pl/), Johnny Mast
- * (http://www.phpvrouwen.nl), T.Wild,
- * http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript,
- * d3x, Michael Grier, Andrea Giammarchi (http://webreflection.blogspot.com),
- * marrtins, Mailfaker (http://www.weedem.fr/), Steve Hilder, gettimeofday,
- * mdsjack (http://www.mdsjack.bo.it), felix, majak, Steven Levithan
- * (http://blog.stevenlevithan.com), Mirek Slugen, Oleg Eremeev, Felix
- * Geisendoerfer (http://www.debuggable.com/felix), Martin
- * (http://www.erlenwiese.de/), gorthaur, Lars Fischer, Joris, AJ, Paul Smith,
- * Tim de Koning (http://www.kingsquare.nl), KELAN, Josh Fraser
- * (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
- * Chris, Marc Palau, Kevin van Zonneveld (http://kevin.vanzonneveld.net/),
- * Arpad Ray (mailto:arpad@php.net), Breaking Par Consulting Inc
- * (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),
- * Nathan, Karol Kowalski, David, Dreamer, Diplom@t (http://difane.com/), Caio
- * Ariede (http://caioariede.com), Robin, Imgen Tata (http://www.myipdf.com/),
- * Pellentesque Malesuada, saulius, Aman Gupta, Sakimori, Tyler Akins
- * (http://rumkin.com), Thunder.m, Public Domain
- * (http://www.json.org/json2.js), Michael White, Kankrelune
- * (http://www.webfaktory.info/), Alfonso Jimenez
- * (http://www.alfonsojimenez.com), Frank Forte, vlado houba, Marco, Billy,
- * David James, madipta, noname, sankai, class_exists, Jalal Berrami, ger,
- * Itsacon (http://www.itsacon.net/), Scott Cariss, nobbler, Arno, Denny
- * Wardhana, ReverseSyntax, Mateusz "loonquawl" Zalega, Slawomir Kaniecki,
- * Francois, Fox, mktime, Douglas Crockford (http://javascript.crockford.com),
- * john (http://www.jd-tech.net), Oskar Larsson Högfeldt
- * (http://oskar-lh.name/), marc andreu, Nick Kolosov (http://sammy.ru), date,
- * Marc Jansen, Steve Clay, Olivier Louvignes (http://mg-crea.com/), Soren
- * Hansen, merabi, Subhasis Deb, josh, T0bsn, Tim Wiel, Brad Touesnard, MeEtc
- * (http://yass.meetcweb.com), Peter-Paul Koch
- * (http://www.quirksmode.org/js/beat.html), Pyerre, Jon Hohle, duncan, Bayron
- * Guevara, Adam Wallner (http://web2.bitbaro.hu/), paulo kuong, Gilbert,
- * Lincoln Ramsay, Thiago Mata (http://thiagomata.blog.com), Linuxworld,
- * lmeyrick (https://sourceforge.net/projects/bcmath-js/this.), djmix, Bryan
- * Elliott, David Randall, Sanjoy Roy, jmweb, Francesco, Stoyan Kyosev
- * (http://www.svest.org/), J A R, kenneth, T. Wild, Ole Vrijenhoek
- * (http://www.nervous.nl/), Raphael (Ao RUDLER), Shingo, LH, JB, nord_ua, jd,
- * JT, Thomas Beaucourt (http://www.webapp.fr), Ozh, XoraX
- * (http://www.xorax.info), EdorFaus, Eugene Bulkin (http://doubleaw.com/),
- * Der Simon (http://innerdom.sourceforge.net/), 0m3r, echo is bad,
- * FremyCompany, stensi, Kristof Coomans (SCK-CEN Belgian Nucleair Research
- * Centre), Devan Penner-Woelk, Pierre-Luc Paour, Martin Pool, Brant Messenger
- * (http://www.brantmessenger.com/), Kirk Strobeck, Saulo Vallory, Christoph,
- * Wagner B. Soares, Artur Tchernychev, Valentina De Rosa, Jason Wong
- * (http://carrot.org/), Daniel Esteban, strftime, Rick Waldron, Mick@el,
- * Anton Ongson, Bjorn Roesbeke (http://www.bjornroesbeke.be/), Simon Willison
- * (http://simonwillison.net), Gabriel Paderni, Philipp Lenssen, Marco van
- * Oort, Bug?, Blues (http://tech.bluesmoon.info/), Tomasz Wesolowski, rezna,
- * Eric Nagel, Evertjan Garretsen, Luke Godfrey, Pul, Bobby Drake, uestla,
- * Alan C, Ulrich, Zahlii, Yves Sucaet, sowberry, Norman "zEh" Fuchs, hitwork,
- * johnrembo, Brian Tafoya (http://www.premasolutions.com/), Nick Callen,
- * Steven Levithan (stevenlevithan.com), ejsanders, Scott Baker, Philippe
- * Jausions (http://pear.php.net/user/jausions), Aidan Lister
- * (http://aidanlister.com/), Rob, e-mike, HKM, ChaosNo1, metjay, strcasecmp,
- * strcmp, Taras Bogach, jpfle, Alexander Ermolaev
- * (http://snippets.dzone.com/user/AlexanderErmolaev), DxGx, kilops, Orlando,
- * dptr1988, Le Torbi, James (http://www.james-bell.co.uk/), Pedro Tainha
- * (http://www.pedrotainha.com), James, penutbutterjelly, Arnout Kazemier
- * (http://www.3rd-Eden.com), 3D-GRAF, daniel airton wermann
- * (http://wermann.com.br), jakes, Yannoo, FGFEmperor, gabriel paderni, Atli
- * Þór, Maximusya, Diogo Resende, Rival, Howard Yeend, Allan Jensen
- * (http://www.winternet.no), davook, Benjamin Lupton, baris ozdil, Greg
- * Frazier, Manish, Matt Bradley, Cord, fearphage
- * (http://http/my.opera.com/fearphage/), Matteo, Victor, taith, Tim de
- * Koning, Ryan W Tenney (http://ryan.10e.us), Tod Gentille, Alexander M
- * Beedie, Riddler (http://www.frontierwebdev.com/), Luis Salazar
- * (http://www.freaky-media.com/), Rafał Kukawski, T.J. Leahy, Luke Smith
- * (http://lucassmith.name), Kheang Hok Chin (http://www.distantia.ca/),
- * Russell Walker (http://www.nbill.co.uk/), Jamie Beck
- * (http://www.terabit.ca/), Garagoth, Andrej Pavlovic, Dino, Le Torbi
- * (http://www.letorbi.de/), Ben (http://benblume.co.uk/), DtTvB
- * (http://dt.in.th/2008-09-16.string-length-in-bytes.html), Michael, Chris
- * McMacken, setcookie, YUI Library:
- * http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Andreas,
- * Blues at http://hacks.bluesmoon.info/strftime/strftime.js, rem, Josep Sanz
- * (http://www.ws3.es/), Cagri Ekin, Lorenzo Pisani, incidence, Amirouche, Jay
- * Klehr, Amir Habibi (http://www.residence-mixte.com/), Tony, booeyOH, meo,
- * William, Greenseed, Yen-Wei Liu, Ben Bryan, Leslie Hoare, mk.keck
- *
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * and GPL (GPL-LICENSE.txt) licenses.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
- * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
- // jslint.com configuration options. See: http://wiki.github.com/kvz/phpjs/jslint-options
- /* global window */
- /* jslint adsafe: false, bitwise: false, browser: false, cap: false, css: false, debug: false, devel: false, eqeqeq: true, evil: false, forin: false, fragment: false, immed: true, indent: 4, laxbreak: false, maxerr: 100, maxlen: 80, newcap: true, nomen: false, on: true, onevar: false, passfail: false, plusplus: false, regexp: false, rhino: false, safe: false, sidebar: false, strict: false, sub: false, undef: true, white: false, widget: false */
-
- // Our idea with CommonJS is that you can do the following:
- // var php = require('php');
- // php.md5('test');
- var php = {};
-
- php.ini_set = function (varname, newvalue) {
- // http://kevin.vanzonneveld.net
- // + original by: Brett Zamir (http://brett-zamir.me)
- // % note 1: This will not set a global_value or access level for the ini item
- // * example 1: ini_set('date.timezone', 'America/Chicago');
- // * returns 1: 'Asia/Hong_Kong'
-
- var oldval = '',
- that = this;
- this.php_js = this.php_js || {};
- this.php_js.ini = this.php_js.ini || {};
- this.php_js.ini[varname] = this.php_js.ini[varname] || {};
- oldval = this.php_js.ini[varname].local_value;
-
- var _setArr = function (oldval) { // Although these are set individually, they are all accumulated
- if (typeof oldval === 'undefined') {
- that.php_js.ini[varname].local_value = [];
- }
- that.php_js.ini[varname].local_value.push(newvalue);
- };
-
- switch (varname) {
- case 'extension':
- if (typeof this.dl === 'function') {
- this.dl(newvalue); // This function is only experimental in php.js
- }
- _setArr(oldval, newvalue);
- break;
- default:
- this.php_js.ini[varname].local_value = newvalue;
- break;
- }
- return oldval;
- };
- php.ini_get = function (varname) {
- // http://kevin.vanzonneveld.net
- // + original by: Brett Zamir (http://brett-zamir.me)
- // % note 1: The ini values must be set by ini_set or manually within an ini file
- // * example 1: ini_get('date.timezone');
- // * returns 1: 'Asia/Hong_Kong'
- if (this.php_js && this.php_js.ini && this.php_js.ini[varname] && this.php_js.ini[varname].local_value !== undefined) {
- if (this.php_js.ini[varname].local_value === null) {
- return '';
- }
- return this.php_js.ini[varname].local_value;
- }
- return '';
- }
-
- php.ctype_digit = function (text) {
- // http://kevin.vanzonneveld.net
- // + original by: Brett Zamir (http://brett-zamir.me)
- // - depends on: setlocale
- // * example 1: ctype_digit('150');
- // * returns 1: true
- if (typeof text !== 'string') {
- return false;
- }
- // BEGIN REDUNDANT
- this.setlocale('LC_ALL', 0); // ensure setup of localization variables takes place
- // END REDUNDANT
- return text.search(this.php_js.locales[this.php_js.localeCategories.LC_CTYPE].LC_CTYPE.dg) !== -1;
- };
- php.gmmktime = function () {
- // http://kevin.vanzonneveld.net
- // + original by: Brett Zamir (http://brett-zamir.me)
- // + derived from: mktime
- // * example 1: gmmktime(14, 10, 2, 2, 1, 2008);
- // * returns 1: 1201875002
- // * example 2: gmmktime(0, 0, -1, 1, 1, 1970);
- // * returns 2: -1
- var d = new Date(),
- r = arguments,
- i = 0,
- e = ['Hours', 'Minutes', 'Seconds', 'Month', 'Date', 'FullYear'];
-
- for (i = 0; i < e.length; i++) {
- if (typeof r[i] === 'undefined') {
- r[i] = d['getUTC' + e[i]]();
- r[i] += (i === 3); // +1 to fix JS months.
- } else {
- r[i] = parseInt(r[i], 10);
- if (isNaN(r[i])) {
- return false;
- }
- }
- }
-
- // Map years 0-69 to 2000-2069 and years 70-100 to 1970-2000.
- r[5] += (r[5] >= 0 ? (r[5] <= 69 ? 2e3 : (r[5] <= 100 ? 1900 : 0)) : 0);
-
- // Set year, month (-1 to fix JS months), and date.
- // !This must come before the call to setHours!
- d.setUTCFullYear(r[5], r[3] - 1, r[4]);
-
- // Set hours, minutes, and seconds.
- d.setUTCHours(r[0], r[1], r[2]);
-
- // Divide milliseconds by 1000 to return seconds and drop decimal.
- // Add 1 second if negative or it'll be off from PHP by 1 second.
- return (d.getTime() / 1e3 >> 0) - (d.getTime() < 0);
- };
- php.getdate = function (timestamp) {
- // http://kevin.vanzonneveld.net
- // + original by: Paulo Freitas
- // + input by: Alex
- // + bugfixed by: Brett Zamir (http://brett-zamir.me)
- // * example 1: getdate(1055901520);
- // * returns 1: {'seconds': 40, 'minutes': 58, 'hours': 21, 'mday': 17, 'wday': 2, 'mon': 6, 'year': 2003, 'yday': 167, 'weekday': 'Tuesday', 'month': 'June', '0': 1055901520}
- var _w = ['Sun', 'Mon', 'Tues', 'Wednes', 'Thurs', 'Fri', 'Satur'];
- var _m = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
- var d = ((typeof(timestamp) == 'undefined') ? new Date() : // Not provided
- (typeof(timestamp) == 'object') ? new Date(timestamp) : // Javascript Date()
- new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
- );
- var w = d.getDay();
- var m = d.getMonth();
- var y = d.getFullYear();
- var r = {};
-
- r.seconds = d.getSeconds();
- r.minutes = d.getMinutes();
- r.hours = d.getHours();
- r.mday = d.getDate();
- r.wday = w;
- r.mon = m + 1;
- r.year = y;
- r.yday = Math.floor((d - (new Date(y, 0, 1))) / 86400000);
- r.weekday = _w[w] + 'day';
- r.month = _m[m];
- r['0'] = parseInt(d.getTime() / 1000, 10);
-
- return r;
- };
- php.checkdate = function (m, d, y) {
- // Returns true(1) if it is a valid date in gregorian calendar
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/checkdate
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Pyerre
- // + improved by: Theriault
- // * example 1: checkdate(12, 31, 2000);
- // * returns 1: true
- // * example 2: checkdate(2, 29, 2001);
- // * returns 2: false
- // * example 3: checkdate(3, 31, 2008);
- // * returns 3: true
- // * example 4: checkdate(1, 390, 2000);
- // * returns 4: false
- return m > 0 && m < 13 && y > 0 && y < 32768 && d > 0 && d <= (new Date(y, m, 0)).getDate();
- };
- php.gmdate = function (format, timestamp) {
- // Format a GMT date/time
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/gmdate
- // + original by: Brett Zamir (http://brett-zamir.me)
- // + input by: Alex
- // + bugfixed by: Brett Zamir (http://brett-zamir.me)
- // - depends on: date
- // * example 1: gmdate('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400); // Return will depend on your timezone
- // * returns 1: '07:09:40 m is month'
- var dt = ((typeof(timestamp) == 'undefined') ? new Date() : // Not provided
- (typeof(timestamp) == 'object') ? new Date(timestamp) : // Javascript Date()
- new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
- );
- timestamp = Date.parse(dt.toUTCString().slice(0, -4)) / 1000;
- return this.date(format, timestamp);
- };
- php.mt_rand = function (min, max) {
- // Returns a random number from Mersenne Twister
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/mt_rand
- // + original by: Onno Marsman
- // * example 1: mt_rand(1, 1);
- // * returns 1: 1
- var argc = arguments.length;
- if (argc === 0) {
- min = 0;
- max = 2147483647;
- } else if (argc === 1) {
- throw new Error('Warning: mt_rand() expects exactly 2 parameters, 1 given');
- }
- return Math.floor(Math.random() * (max - min + 1)) + min;
- };
-
- php.abs = function (mixed_number) {
- // Return the absolute value of the number
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/abs
- // + original by: Waldo Malqui Silva
- // + improved by: Karol Kowalski
- // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
- // * example 1: \php.abs(4.2);
- // * returns 1: 4.2
- // * example 2: \php.abs(-4.2);
- // * returns 2: 4.2
- // * example 3: \php.abs(-5);
- // * returns 3: 5
- // * example 4: \php.abs('_argos');
- // * returns 4: 0
- return Math.abs(mixed_number) || 0;
- };
-
- php.addcslashes = function (str, charlist) {
- // Escapes all chars mentioned in charlist with backslash. It creates octal representations if asked to backslash characters with 8th bit set or with ASCII<32 (except '\n', '\r', '\t' etc...)
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/addcslashes
- // + original by: Brett Zamir (http://brett-zamir.me)
- // % note 1: We show double backslashes in the return value example code below because a JavaScript string will not
- // % note 1: render them as backslashes otherwise
- // * example 1: \php.addcslashes('foo[ ]', 'A..z'); // Escape all ASCII within capital A to lower z range, including square brackets
- // * returns 1: "\\f\\o\\o\\[ \\]"
- // * example 2: \php.addcslashes("zoo['.']", 'z..A'); // Only escape z, period, and A here since not a lower-to-higher range
- // * returns 2: "\\zoo['\\.']"
- // * example 3: \php.addcslashes("@a\u0000\u0010\u00A9", "\0..\37!@\177..\377") == '\\@a\\000\\020\\302\\251'); // Escape as octals those specified and less than 32 (0x20) or greater than 126 (0x7E), but not otherwise
- // * returns 3: true
- // * example 4: \php.addcslashes("\u0020\u007E", "\40..\175") == '\\ ~'); // Those between 32 (0x20 or 040) and 126 (0x7E or 0176) decimal value will be backslashed if specified (not octalized)
- // * returns 4: true
- // * example 5: \php.addcslashes("\r\u0007\n", '\0..\37'); // Recognize C escape sequences if specified
- // * returns 5: "\\r\\a\\n"
- // * example 6: \php.addcslashes("\r\u0007\n", '\0'); // Do not recognize C escape sequences if not specified
- // * returns 7: "\r\u0007\n"
- var target = '',
- chrs = [],
- i = 0,
- j = 0,
- c = '',
- next = '',
- rangeBegin = '',
- rangeEnd = '',
- chr = '',
- begin = 0,
- end = 0,
- octalLength = 0,
- postOctalPos = 0,
- cca = 0,
- escHexGrp = [],
- encoded = '',
- percentHex = /%([\dA-Fa-f]+)/g;
- var _pad = function (n, c) {
- if ((n = n + "").length < c) {
- return new Array(++c - n.length).join("0") + n;
- } else {
- return n;
- }
- };
-
- for (i = 0; i < charlist.length; i++) {
- c = charlist.charAt(i);
- next = charlist.charAt(i + 1);
- if (c === '\\' && next && (/\d/).test(next)) { // Octal
- rangeBegin = charlist.slice(i + 1).match(/^\d+/)[0];
- octalLength = rangeBegin.length;
- postOctalPos = i + octalLength + 1;
- if (charlist.charAt(postOctalPos) + charlist.charAt(postOctalPos + 1) === '..') { // Octal begins range
- begin = rangeBegin.charCodeAt(0);
- if ((/\\\d/).test(charlist.charAt(postOctalPos + 2) + charlist.charAt(postOctalPos + 3))) { // Range ends with octal
- rangeEnd = charlist.slice(postOctalPos + 3).match(/^\d+/)[0];
- i += 1; // Skip range end backslash
- } else if (charlist.charAt(postOctalPos + 2)) { // Range ends with character
- rangeEnd = charlist.charAt(postOctalPos + 2);
- } else {
- throw 'Range with no end point';
- }
- end = rangeEnd.charCodeAt(0);
- if (end > begin) { // Treat as a range
- for (j = begin; j <= end; j++) {
- chrs.push(String.fromCharCode(j));
- }
- } else { // Supposed to treat period, begin and end as individual characters only, not a range
- chrs.push('.', rangeBegin, rangeEnd);
- }
- i += rangeEnd.length + 2; // Skip dots and range end (already skipped range end backslash if present)
- } else { // Octal is by itself
- chr = String.fromCharCode(parseInt(rangeBegin, 8));
- chrs.push(chr);
- }
- i += octalLength; // Skip range begin
- } else if (next + charlist.charAt(i + 2) === '..') { // Character begins range
- rangeBegin = c;
- begin = rangeBegin.charCodeAt(0);
- if ((/\\\d/).test(charlist.charAt(i + 3) + charlist.charAt(i + 4))) { // Range ends with octal
- rangeEnd = charlist.slice(i + 4).match(/^\d+/)[0];
- i += 1; // Skip range end backslash
- } else if (charlist.charAt(i + 3)) { // Range ends with character
- rangeEnd = charlist.charAt(i + 3);
- } else {
- throw 'Range with no end point';
- }
- end = rangeEnd.charCodeAt(0);
- if (end > begin) { // Treat as a range
- for (j = begin; j <= end; j++) {
- chrs.push(String.fromCharCode(j));
- }
- } else { // Supposed to treat period, begin and end as individual characters only, not a range
- chrs.push('.', rangeBegin, rangeEnd);
- }
- i += rangeEnd.length + 2; // Skip dots and range end (already skipped range end backslash if present)
- } else { // Character is by itself
- chrs.push(c);
- }
- }
-
- for (i = 0; i < str.length; i++) {
- c = str.charAt(i);
- if (chrs.indexOf(c) !== -1) {
- target += '\\';
- cca = c.charCodeAt(0);
- if (cca < 32 || cca > 126) { // Needs special escaping
- switch (c) {
- case '\n':
- target += 'n';
- break;
- case '\t':
- target += 't';
- break;
- case '\u000D':
- target += 'r';
- break;
- case '\u0007':
- target += 'a';
- break;
- case '\v':
- target += 'v';
- break;
- case '\b':
- target += 'b';
- break;
- case '\f':
- target += 'f';
- break;
- default:
- //target += _pad(cca.toString(8), 3);break; // Sufficient for UTF-16
- encoded = encodeURIComponent(c);
-
- // 3-length-padded UTF-8 octets
- if ((escHexGrp = percentHex.exec(encoded)) !== null) {
- target += _pad(parseInt(escHexGrp[1], 16).toString(8), 3); // already added a slash above
- }
- while ((escHexGrp = percentHex.exec(encoded)) !== null) {
- target += '\\' + _pad(parseInt(escHexGrp[1], 16).toString(8), 3);
- }
- break;
- }
- } else { // Perform regular backslashed escaping
- target += c;
- }
- } else { // Just add the character unescaped
- target += c;
- }
- }
- return target;
- };
-
- php.addslashes = function (str) {
- // Escapes single quote, double quotes and backslash characters in a string with backslashes
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/addslashes
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Ates Goral (http://magnetiq.com)
- // + improved by: marrtins
- // + improved by: Nate
- // + improved by: Onno Marsman
- // + input by: Denny Wardhana
- // + improved by: Brett Zamir (http://brett-zamir.me)
- // + improved by: Oskar Larsson Högfeldt (http://oskar-lh.name/)
- // * example 1: \php.addslashes("kevin's birthday");
- // * returns 1: 'kevin\'s birthday'
- return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
- };
-
- php.array_chunk = function (input, size) {
- // Split array into chunks
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_chunk
- // + original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
- // * example 1: \php.array_chunk(['Kevin', 'van', 'Zonneveld'], 2);
- // * returns 1: {0 : {0: 'Kevin', 1: 'van'} , 1 : {0: 'Zonneveld'}}
- for (var x, i = 0, c = -1, l = input.length, n = []; i < l; i++) {
- (x = i % size) ? n[c][x] = input[i] : n[++c] = [input[i]];
- }
-
- return n;
- };
-
- php.array_combine = function (keys, values) {
- // Creates an array by using the elements of the first parameter as keys and the elements of the second as the corresponding values
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_combine
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Brett Zamir (http://brett-zamir.me)
- // * example 1: \php.array_combine([0,1,2], ['kevin','van','zonneveld']);
- // * returns 1: {0: 'kevin', 1: 'van', 2: 'zonneveld'}
- var new_array = {},
- keycount = keys && keys.length,
- i = 0;
-
- // input sanitation
- if (typeof keys !== 'object' || typeof values !== 'object' || // Only accept arrays or array-like objects
- typeof keycount !== 'number' || typeof values.length !== 'number' || !keycount) { // Require arrays to have a count
- return false;
- }
-
- // number of elements does not match
- if (keycount != values.length) {
- return false;
- }
-
- for (i = 0; i < keycount; i++) {
- new_array[keys[i]] = values[i];
- }
-
- return new_array;
- };
-
- php.array_diff = function () {
- // Returns the entries of arr1 that have values which are not present in any of the others arguments.
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_diff
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Sanjoy Roy
- // + revised by: Brett Zamir (http://brett-zamir.me)
- // * example 1: \php.array_diff(['Kevin', 'van', 'Zonneveld'], ['van', 'Zonneveld']);
- // * returns 1: {0:'Kevin'}
- var arr1 = arguments[0],
- retArr = {};
- var k1 = '',
- i = 1,
- k = '',
- arr = {};
-
- arr1keys: for (k1 in arr1) {
- for (i = 1; i < arguments.length; i++) {
- arr = arguments[i];
- for (k in arr) {
- if (arr[k] === arr1[k1]) {
- // If it reaches here, it was found in at least one array, so try next value
- continue arr1keys;
- }
- }
- retArr[k1] = arr1[k1];
- }
- }
-
- return retArr;
- };
-
- php.array_fill = function (start_index, num, mixed_val) {
- // Create an array containing num elements starting with index start_key each initialized to val
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_fill
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Waldo Malqui Silva
- // * example 1: \php.array_fill(5, 6, 'banana');
- // * returns 1: { 5: 'banana', 6: 'banana', 7: 'banana', 8: 'banana', 9: 'banana', 10: 'banana' }
- var key, tmp_arr = {};
-
- if (!isNaN(start_index) && !isNaN(num)) {
- for (key = 0; key < num; key++) {
- tmp_arr[(key + start_index)] = mixed_val;
- }
- }
-
- return tmp_arr;
- };
-
- php.array_fill_keys = function (keys, value) {
- // Create an array using the elements of the first parameter as keys each initialized to val
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_fill_keys
- // + original by: Brett Zamir (http://brett-zamir.me)
- // + bugfixed by: Brett Zamir (http://brett-zamir.me)
- // * example 1: \php.keys = {'a': 'foo', 2: 5, 3: 10, 4: 'bar'}
- // * example 1: \php.array_fill_keys(keys, 'banana')
- // * returns 1: {"foo": "banana", 5: "banana", 10: "banana", "bar": "banana"}
- var retObj = {},
- key = '';
-
- for (key in keys) {
- retObj[keys[key]] = value;
- }
-
- return retObj;
- };
-
- php.array_filter = function (arr, func) {
- // Filters elements from the array via the callback.
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_filter
- // + original by: Brett Zamir (http://brett-zamir.me)
- // % note 1: Takes a function as an argument, not a function's name
- // * example 1: \php.var odd = function (num) {return (num & 1);};
- // * example 1: \php.array_filter({"a": 1, "b": 2, "c": 3, "d": 4, "e": 5}, odd);
- // * returns 1: {"a": 1, "c": 3, "e": 5}
- // * example 2: \php.var even = function (num) {return (!(num & 1));}
- // * example 2: \php.array_filter([6, 7, 8, 9, 10, 11, 12], even);
- // * returns 2: {0: 6, 2: 8, 4: 10, 6: 12}
- var retObj = {},
- k;
-
- for (k in arr) {
- if (func(arr[k])) {
- retObj[k] = arr[k];
- }
- }
-
- return retObj;
- };
-
- php.array_flip = function (trans) {
- // Return array with key <-> value flipped
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_flip
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // * example 1: \php.array_flip( {a: 1, b: 1, c: 2} );
- // * returns 1: {1: 'b', 2: 'c'}
- var key, tmp_ar = {};
-
- for (key in trans) {
- tmp_ar[trans[key]] = key;
- }
-
- return tmp_ar;
- };
-
- php.array_intersect = function () {
- // Returns the entries of arr1 that have values which are present in all the other arguments
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_intersect
- // + original by: Brett Zamir (http://brett-zamir.me)
- // % note 1: These only output associative arrays (would need to be
- // % note 1: all numeric and counting from zero to be numeric)
- // * example 1: $array1 = {'a' : 'green', 0:'red', 1: 'blue'};
- // * example 1: $array2 = {'b' : 'green', 0:'yellow', 1:'red'};
- // * example 1: $array3 = ['green', 'red'];
- // * example 1: $result = array_intersect($array1, $array2, $array3);
- // * returns 1: {0: 'red', a: 'green'}
- var arr1 = arguments[0],
- retArr = {};
- var k1 = '',
- arr = {},
- i = 0,
- k = '';
-
- arr1keys: for (k1 in arr1) {
- arrs: for (i = 1; i < arguments.length; i++) {
- arr = arguments[i];
- for (k in arr) {
- if (arr[k] === arr1[k1]) {
- if (i === arguments.length - 1) {
- retArr[k1] = arr1[k1];
- }
- // If the innermost loop always leads at least once to an equal value, continue the loop until done
- continue arrs;
- }
- }
- // If it reaches here, it wasn't found in at least one array, so try next value
- continue arr1keys;
- }
- }
-
- return retArr;
- };
-
- php.array_key_exists = function (key, search) {
- // Checks if the given key or index exists in the array
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_key_exists
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)
- // * example 1: \php.array_key_exists('kevin', {'kevin': 'van Zonneveld'});
- // * returns 1: true
- // input sanitation
- if (!search || (search.constructor !== Array && search.constructor !== Object)) {
- return false;
- }
-
- return key in search;
- };
-
- php.array_keys = function (input, search_value, argStrict) {
- // Return just the keys from the input array, optionally only for the specified search_value
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_keys
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + input by: Brett Zamir (http://brett-zamir.me)
- // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: jd
- // + improved by: Brett Zamir (http://brett-zamir.me)
- // * example 1: \php.array_keys( {firstname: 'Kevin', surname: 'van Zonneveld'} );
- // * returns 1: {0: 'firstname', 1: 'surname'}
- var search = typeof search_value !== 'undefined',
- tmp_arr = [],
- strict = !!argStrict,
- include = true,
- key = '';
-
- for (key in input) {
- if (input.hasOwnProperty(key)) {
- include = true;
- if (search) {
- if (strict && input[key] !== search_value) {
- include = false;
- }
- else if (input[key] != search_value) {
- include = false;
- }
- }
-
- if (include) {
- tmp_arr[tmp_arr.length] = key;
- }
- }
- }
-
- return tmp_arr;
- };
-
- php.array_map = function (callback) {
- // Applies the callback to the elements in given arrays.
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_map
- // + original by: Andrea Giammarchi (http://webreflection.blogspot.com)
- // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Brett Zamir (http://brett-zamir.me)
- // % note 1: Takes a function as an argument, not a function's name
- // % note 2: If the callback is a string, it can only work if the function name is in the global context
- // * example 1: \php.array_map( function (a){return (a * a * a)}, [1, 2, 3, 4, 5] );
- // * returns 1: [ 1, 8, 27, 64, 125 ]
- var argc = arguments.length,
- argv = arguments;
- var j = argv[1].length,
- i = 0,
- k = 1,
- m = 0;
- var tmp = [],
- tmp_ar = [];
-
- while (i < j) {
- while (k < argc) {
- tmp[m++] = argv[k++][i];
- }
-
- m = 0;
- k = 1;
-
- if (callback) {
- if (typeof callback === 'string') {
- callback = this.window[callback];
- }
- tmp_ar[i++] = callback.apply(null, tmp);
- } else {
- tmp_ar[i++] = tmp;
- }
-
- tmp = [];
- }
-
- return tmp_ar;
- };
-
- php.array_merge = function () {
- // Merges elements from passed arrays into one array
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_merge
- // + original by: Brett Zamir (http://brett-zamir.me)
- // + bugfixed by: Nate
- // + input by: josh
- // + bugfixed by: Brett Zamir (http://brett-zamir.me)
- // * example 1: \php.arr1 = {"color": "red", 0: 2, 1: 4}
- // * example 1: \php.arr2 = {0: "a", 1: "b", "color": "green", "shape": "trapezoid", 2: 4}
- // * example 1: \php.array_merge(arr1, arr2)
- // * returns 1: {"color": "green", 0: 2, 1: 4, 2: "a", 3: "b", "shape": "trapezoid", 4: 4}
- // * example 2: \php.arr1 = []
- // * example 2: \php.arr2 = {1: "data"}
- // * example 2: \php.array_merge(arr1, arr2)
- // * returns 2: {0: "data"}
- var args = Array.prototype.slice.call(arguments),
- retObj = {},
- k, j = 0,
- i = 0,
- retArr = true;
-
- for (i = 0; i < args.length; i++) {
- if (!(args[i] instanceof Array)) {
- retArr = false;
- break;
- }
- }
-
- if (retArr) {
- retArr = [];
- for (i = 0; i < args.length; i++) {
- retArr = retArr.concat(args[i]);
- }
- return retArr;
- }
- var ct = 0;
-
- for (i = 0, ct = 0; i < args.length; i++) {
- if (args[i] instanceof Array) {
- for (j = 0; j < args[i].length; j++) {
- retObj[ct++] = args[i][j];
- }
- } else {
- for (k in args[i]) {
- if (args[i].hasOwnProperty(k)) {
- if (parseInt(k, 10) + '' === k) {
- retObj[ct++] = args[i][k];
- } else {
- retObj[k] = args[i][k];
- }
- }
- }
- }
- }
- return retObj;
- };
-
- php.array_merge_recursive = function (arr1, arr2) {
- // Recursively merges elements from passed arrays into one array
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_merge_recursive
- // + original by: Subhasis Deb
- // + input by: Brett Zamir (http://brett-zamir.me)
- // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // - depends on: array_merge
- // * example 1: \php.arr1 = {'color': {'favourite': 'read'}, 0: 5}
- // * example 1: \php.arr2 = {0: 10, 'color': {'favorite': 'green', 0: 'blue'}}
- // * example 1: \php.array_merge_recursive(arr1, arr2)
- // * returns 1: {'color': {'favorite': {0: 'red', 1: 'green'}, 0: 'blue'}, 1: 5, 1: 10}
- var idx = '';
-
- if ((arr1 && (arr1 instanceof Array)) && (arr2 && (arr2 instanceof Array))) {
- for (idx in arr2) {
- arr1.push(arr2[idx]);
- }
- } else if ((arr1 && (arr1 instanceof Object)) && (arr2 && (arr2 instanceof Object))) {
- for (idx in arr2) {
- if (idx in arr1) {
- if (typeof arr1[idx] == 'object' && typeof arr2 == 'object') {
- arr1[idx] = this.array_merge(arr1[idx], arr2[idx]);
- } else {
- arr1[idx] = arr2[idx];
- }
- } else {
- arr1[idx] = arr2[idx];
- }
- }
- }
-
- return arr1;
- };
-
- php.array_pop = function (inputArr) {
- // Pops an element off the end of the array
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_pop
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + input by: Brett Zamir (http://brett-zamir.me)
- // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + bugfixed by: Brett Zamir (http://brett-zamir.me)
- // + input by: Theriault
- // % note 1: While IE (and other browsers) support iterating an object's
- // % note 1: own properties in order, if one attempts to add back properties
- // % note 1: in IE, they may end up in their former position due to their position
- // % note 1: being retained. So use of this function with "associative arrays"
- // % note 1: (objects) may lead to unexpected behavior in an IE environment if
- // % note 1: you add back properties with the same keys that you removed
- // * example 1: \php.array_pop([0,1,2]);
- // * returns 1: 2
- // * example 2: \php.data = {firstName: 'Kevin', surName: 'van Zonneveld'};
- // * example 2: \php.lastElem = array_pop(data);
- // * returns 2: 'van Zonneveld'
- // * results 2: data == {firstName: 'Kevin'}
- var key = '',
- lastKey = '';
-
- if (inputArr.hasOwnProperty('length')) {
- // Indexed
- if (!inputArr.length) {
- // Done popping, are we?
- return null;
- }
- return inputArr.pop();
- } else {
- // Associative
- for (key in inputArr) {
- if (inputArr.hasOwnProperty(key)) {
- lastKey = key;
- }
- }
- if (lastKey) {
- var tmp = inputArr[lastKey];
- delete(inputArr[lastKey]);
- return tmp;
- } else {
- return null;
- }
- }
- };
-
- php.array_push = function (inputArr) {
- // Pushes elements onto the end of the array
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_push
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Brett Zamir (http://brett-zamir.me)
- // % note 1: Note also that IE retains information about property position even
- // % note 1: after being supposedly deleted, so if you delete properties and then
- // % note 1: add back properties with the same keys (including numeric) that had
- // % note 1: been deleted, the order will be as before; thus, this function is not
- // % note 1: really recommended with associative arrays (objects) in IE environments
- // * example 1: \php.array_push(['kevin','van'], 'zonneveld');
- // * returns 1: 3
- var i = 0,
- pr = '',
- argv = arguments,
- argc = argv.length,
- allDigits = /^\d$/,
- size = 0,
- highestIdx = 0,
- len = 0;
- if (inputArr.hasOwnProperty('length')) {
- for (i = 1; i < argc; i++) {
- inputArr[inputArr.length] = argv[i];
- }
- return inputArr.length;
- }
-
- // Associative (object)
- for (pr in inputArr) {
- if (inputArr.hasOwnProperty(pr)) {
- ++len;
- if (pr.search(allDigits) !== -1) {
- size = parseInt(pr, 10);
- highestIdx = size > highestIdx ? size : highestIdx;
- }
- }
- }
- for (i = 1; i < argc; i++) {
- inputArr[++highestIdx] = argv[i];
- }
- return len + i - 1;
- };
-
- php.array_reduce = function (a_input, callback) {
- // Iteratively reduce the array to a single value via the callback.
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_reduce
- // + original by: Alfonso Jimenez (http://www.alfonsojimenez.com)
- // % note 1: Takes a function as an argument, not a function's name
- // * example 1: \php.array_reduce([1, 2, 3, 4, 5], function (v, w){v += w;return v;});
- // * returns 1: 15
- var lon = a_input.length;
- var res = 0,
- i = 0;
- var tmp = [];
-
-
- for (i = 0; i < lon; i += 2) {
- tmp[0] = a_input[i];
- if (a_input[(i + 1)]) {
- tmp[1] = a_input[(i + 1)];
- } else {
- tmp[1] = 0;
- }
- res += callback.apply(null, tmp);
- tmp = [];
- }
-
- return res;
- };
-
- php.array_reverse = function (array, preserve_keys) {
- // Return input as a new array with the order of the entries reversed
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_reverse
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Karol Kowalski
- // * example 1: \php.array_reverse( [ 'php', '4.0', ['green', 'red'] ], true);
- // * returns 1: { 2: ['green', 'red'], 1: 4, 0: 'php'}
- var arr_len = array.length,
- newkey = 0,
- tmp_arr = {},
- key = '';
- preserve_keys = !! preserve_keys;
-
- for (key in array) {
- newkey = arr_len - key - 1;
- tmp_arr[preserve_keys ? key : newkey] = array[key];
- }
-
- return tmp_arr;
- };
-
- php.array_shift = function (inputArr) {
- // Pops an element off the beginning of the array
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_shift
- // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Martijn Wieringa
- // % note 1: Currently does not handle objects
- // * example 1: \php.array_shift(['Kevin', 'van', 'Zonneveld']);
- // * returns 1: 'Kevin'
- var props = false,
- shift = undefined,
- pr = '',
- allDigits = /^\d$/,
- int_ct = -1,
- _checkToUpIndices = function (arr, ct, key) {
- // Deal with situation, e.g., if encounter index 4 and try to set it to 0, but 0 exists later in loop (need to
- // increment all subsequent (skipping current key, since we need its value below) until find unused)
- if (arr[ct] !== undefined) {
- var tmp = ct;
- ct += 1;
- if (ct === key) {
- ct += 1;
- }
- ct = _checkToUpIndices(arr, ct, key);
- arr[ct] = arr[tmp];
- delete arr[tmp];
- }
- return ct;
- };
-
-
- if (inputArr.length === 0) {
- return null;
- }
- if (inputArr.length > 0) {
- return inputArr.shift();
- }
-
- /*
- UNFINISHED FOR HANDLING OBJECTS
- for (pr in inputArr) {
- if (inputArr.hasOwnProperty(pr)) {
- props = true;
- shift = inputArr[pr];
- delete inputArr[pr];
- break;
- }
- }
- for (pr in inputArr) {
- if (inputArr.hasOwnProperty(pr)) {
- if (pr.search(allDigits) !== -1) {
- int_ct += 1;
- if (parseInt(pr, 10) === int_ct) { // Key is already numbered ok, so don't need to change key for value
- continue;
- }
- _checkToUpIndices(inputArr, int_ct, pr);
- arr[int_ct] = arr[pr];
- delete arr[pr];
- }
- }
- }
- if (!props) {
- return null;
- }
- return shift;
- */
- };
-
- php.array_slice = function (arr, offst, lgth, preserve_keys) {
- // Returns elements specified by offset and length
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_slice
- // + original by: Brett Zamir (http://brett-zamir.me)
- // - depends on: is_int
- // + input by: Brett Zamir (http://brett-zamir.me)
- // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // % note: Relies on is_int because !isNaN accepts floats
- // * example 1: \php.array_slice(["a", "b", "c", "d", "e"], 2, -1);
- // * returns 1: {0: 'c', 1: 'd'}
- // * example 2: \php.array_slice(["a", "b", "c", "d", "e"], 2, -1, true);
- // * returns 2: {2: 'c', 3: 'd'}
- /*
- if ('callee' in arr && 'length' in arr) {
- arr = Array.prototype.slice.call(arr);
- }
- */
-
- var key = '';
-
- if (!(arr instanceof Array) || (preserve_keys && offst !== 0)) { // Assoc. array as input or if required as output
- var lgt = 0,
- newAssoc = {};
- for (key in arr) {
- //if (key !== 'length') {
- lgt += 1;
- newAssoc[key] = arr[key];
- //}
- }
- arr = newAssoc;
-
- offst = (offst < 0) ? lgt + offst : offst;
- lgth = lgth === undefined ? lgt : (lgth < 0) ? lgt + lgth - offst : lgth;
-
- var assoc = {};
- var start = false,
- it = -1,
- arrlgth = 0,
- no_pk_idx = 0;
- for (key in arr) {
- ++it;
- if (arrlgth >= lgth) {
- break;
- }
- if (it == offst) {
- start = true;
- }
- if (!start) {
- continue;
- }++arrlgth;
- if (this.is_int(key) && !preserve_keys) {
- assoc[no_pk_idx++] = arr[key];
- } else {
- assoc[key] = arr[key];
- }
- }
- //assoc.length = arrlgth; // Make as array-like object (though length will not be dynamic)
- return assoc;
- }
-
- if (lgth === undefined) {
- return arr.slice(offst);
- } else if (lgth >= 0) {
- return arr.slice(offst, offst + lgth);
- } else {
- return arr.slice(offst, lgth);
- }
- };
-
- php.array_splice = function (arr, offst, lgth, replacement) {
- // Removes the elements designated by offset and length and replace them with supplied array
- //
- // version: 1103.1210
- // discuss at: http://phpjs.org/functions/array_splice
- // + original by: Brett Zamir (http://brett-zamir.me)
- // + input by: Theriault
- // % note 1: Order does get shifted in associative array input with numeric indices,
- // % note 1: since PHP behavior doesn't preserve keys, but I understand order is
- // % note 1: not reliable anyways
- // % note 2: Note also that IE retains information about property position even
- // % note 2: after being supposedly deleted, so use of this function may produce
- // % note 2: unexpected results in IE if you later attempt to add back properties
- // % note 2: with the same keys that had been deleted
- // - depends on: is_int
- // * example 1: \php.input = {4: "red", 'abc': "green", 2: "blue", 'dud': "yellow"};
- // * example 1: \php.array_splice(input, 2);
- // * returns 1: {0: "blue", 'dud': "yellow"}
- // * results 1: input == {'abc':"green", 0:"red"}
- // * example 2: \php.input = ["red", "green", "blue", "yellow"];
- // …
Large files files are truncated, but you can click here to view the full file