Javascript equivalent of PHP’s list()

There is, in ‘newer’ versions of Javascript: Destructuring assignment – Javascript 1.7. It’s probably only supported in Mozilla-based browsers, and maybe in Rhino. var a = 1; var b = 3; [a, b] = [b, a]; EDIT: actually it wouldn’t surprise me if the V8 Javascript library (and thus Chrome) supports this. But don’t count … Read more

nl2br() equivalent in javascript [duplicate]

Take a look at nl2br on php.js which seems exactly what you’re looking for. Basically, it’s: function nl2br (str, is_xhtml) { if (typeof str === ‘undefined’ || str === null) { return ”; } var breakTag = (is_xhtml || typeof is_xhtml === ‘undefined’) ? ‘<br />’ : ‘<br>’; return (str + ”).replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, ‘$1’ + breakTag … Read more

JavaScript equivalent of PHP’s in_array()

No, it doesn’t have one. For this reason most popular libraries come with one in their utility packages. Check out jQuery’s inArray and Prototype’s Array.indexOf for examples. jQuery’s implementation of it is as simple as you might expect: function inArray(needle, haystack) { var length = haystack.length; for(var i = 0; i < length; i++) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)