Pass a PHP variable to a JavaScript variable

Expanding on someone else’s answer: <script> var myvar = <?= json_encode($myVarValue, JSON_UNESCAPED_UNICODE); ?>; </script> Using json_encode() requires: PHP 5.2.0 or greater $myVarValue encoded as UTF-8 (or US-ASCII, of course) Since UTF-8 supports full Unicode, it should be safe to convert on the fly. Please note that if you use this in html attributes like onclick, … Read more

Notepad++ Regex Backreference syntax in Search/Replace – \1 or $1

Notepad++’s earlier versions (v5.9.8 and prior) only supported standard POSIX Regular Expressions. However, full PCRE (Perl Compatible Regular Expression) Search/Replace support was added in version 6.0: New features and enhancement in Notepad++ 6.0: PCRE (Perl Compatible Regular Expressions) is supported. This means that if you’re using Notepad++ v6.0 or any newer version (e.g v6.1.5), you … Read more

Curl – Exclamation mark in User Auth/Password

curl -u UserName\\WithSlash:PasswordWithExclamation\! http://…. works fine. it sends GET / HTTP/1.1 Authorization: Basic VXNlck5hbWVcV2l0aFNsYXNoOlBhc3N3b3JkV2l0aEV4Y2xhbWF0aW9uIQ== User-Agent: curl/7.21.0 Host: teststuff1.com:80 Accept: */* which is “UserName\WithSlash:PasswordWithExclamation!” in the auth string.

How can I put double quotes inside a string within an ajax JSON response from php?

Just escape it with a backslash: > JSON.stringify({“a”: 5, “b”: ‘a “kitty” mighty odd’}) {“a”:5,”b”:”a \”kitty\” mighty odd”} > JSON.parse(‘{“a”:5,”b”:”a \\”kitty\\” mighty odd”}’) Object a: 5 b: a “kitty” mighty odd __proto__: Object JSON parsers recognize \” inside double-quoted strings as a double quote. Note that in the second example, the double-backslash is needed because … Read more

How to remove backslash escaping from a javascript var?

You can replace a backslash followed by a quote with just a quote via a regular expression and the String#replace function: var x = “<div class=\\\”abcdef\\\”>”; x = x.replace(/\\”/g, ‘”‘); document.body.appendChild( document.createTextNode(“After: ” + x) ); Note that the regex just looks for one backslash; there are two in the literal because you have to … Read more

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