144
votes
13answers
94k views
Pass a PHP string to a Javascript variable (and escape newlines)
What is the easiest way to encode a PHP string for output to a Javascript variable?
I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a ...
97
votes
7answers
73k views
Is there an equivalent for var_dump (PHP) in Javascript?
We need to see what methods/fields an object has in Javascript.
92
votes
9answers
63k views
Javascript Equivalent to PHP Explode()
I have a string that looks like this:
0000000020C90037:TEMP:data
And I need to grab everything after the first colon, so that I have TEMP:data, forgive me I don't often work in Javascript if it ...
73
votes
11answers
62k views
JavaScript equivalent of PHP's in_array()
Is there a way in JavaScript to compare values from one array and see if it is in another array?
Similar to PHP's in_array function?
63
votes
2answers
1k views
Where can I find unit tests for regular expressions in multiple languages?
I'm building a regex helper at http://www.debuggex.com. The amount of detail I want to show requires me to write my own parser and matcher.
To make sure my parser and matcher work correctly, I've ...
58
votes
11answers
85k views
Resize iframe height according to content height in it
I am opening my blog page in my website. The problem is I can give a width to an iframe but the height should be dynamic so that there is no scrollbar in the iframe, and it looks like a single page...
...
57
votes
25answers
70k views
How can I compare two sets of 1000 numbers against each other?
I must check approximately 1000 numbers against 1000 other numbers.
I loaded both and compared them server-side:
foreach( $numbers1 as $n1 ) {
foreach( $numbers2 as $n2 ) {
if( $n1 == $n2 ) {
...
42
votes
7answers
14k views
Multiple javascript/css files: best practices?
I have about 7 Javascript files now (thanks to various jQuery plugins) and 4-5 CSS files. I'm curious as to what's the best practice for dealing with these including where in the document they should ...
41
votes
6answers
18k views
Convert MySql DateTime stamp into JavaScript's Date format
Does anyone know how I can take a mysql datetime stamp, such as YYYY-MM-DD HH:MM:SS and either parse it or convert it to work in JavaScript's Date() function, such as.. Date('YYYY, MM, DD, HH, MM, ...
39
votes
3answers
2k views
Javascript closures vs PHP closures, what's the difference?
What are the differences between closures in JS and closures in PHP? Do they pretty much work the same way? Are there any caveats to be aware of when writing closures in PHP?
37
votes
9answers
2k views
User recognition without cookies or local storage
I'm building an analytic tool and I can currently get the user's IP address, browser and operating system from their user agent.
I'm wondering if there is a possibility to detect the same user ...
37
votes
5answers
20k views
How to properly handle session and access token with Facebook PHP SDK 3.0?
In the PHP 3.0 SDK there is no getSession() or any session handling from outside the Facebook api available. Some days ago the developers of facebook have also somehow updated the JavaScript sdk, ...
35
votes
5answers
55k views
json parse error with double quotes
A double quote even if escaped is throwing parse error.
look at the code below
//parse the json in javascript
var testJson = '{"result": ["lunch", "\"Show\""] }';
var tags = JSON.parse(testJson); ...
35
votes
13answers
5k views
Tell bots apart from human visitors for stats?
I am looking to roll my own simple web stats script.
The only major obstacle on the road, as far as I can see, is telling human visitors apart from bots. I would like to have a solution for that ...
33
votes
3answers
64k views
Returning JSON from PHP to JavaScript?
I have a PHP script that's being called through jQuery AJAX. I want the PHP script to return the data in JSON format to the javascript. Here's the pseudo code in the PHP script:
$json = "{";
...