Tagged Questions
135
votes
14answers
85k 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 ...
85
votes
7answers
66k views
Is there an equivalent for var_dump (PHP) in Javascript?
We need to see what methods/fields an object has in Javascript.
75
votes
9answers
48k 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 ...
66
votes
10answers
55k 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?
60
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 ...
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 ) {
...
52
votes
11answers
80k 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...
...
42
votes
7answers
13k 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 ...
37
votes
5answers
19k 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, ...
34
votes
6answers
15k 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, ...
34
votes
3answers
1k 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?
34
votes
5answers
53k 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); ...
31
votes
3answers
57k 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 = "{";
...
31
votes
13answers
4k 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 ...
31
votes
4answers
704 views
How does similar_text work?
I just found the similar_text function and was playing around with it, but the percentage output always suprises me. See the examples below.
I tried to find information on the algorithm used as ...