140
votes
13answers
89k 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 ...
38
votes
6answers
16k 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, ...
32
votes
9answers
1k 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 ...
29
votes
12answers
14k views

PHP json_encode encoding numbers as strings

I am having one problem with the PHP json_encode function. It encodes numbers as strings (e.g. array('id' => 3 becomes "{ ["id": "3", ...) When js encounters these values, it interprets them as ...
22
votes
4answers
7k views

Javascript equivalent of PHP's list()

Really like that function. $matches = array('12', 'watt'); list($value, $unit) = $matches; Is there a Javascript equivalent of that?
14
votes
5answers
4k views

PHP Ajax Upload Progress Bar

<form enctype="multipart/form-data" action="upload.php" method="POST"> <input name="uploaded" type="file" /> <input type="submit" value="Upload" /> </form> <?php ...
12
votes
6answers
34k views

Convert php array to Javascript

How can I convert a PHP array in a format like this Array ( [0] => 001-1234567 [1] => 1234567 [2] => 12345678 [3] => 12345678 [4] => 12345678 [5] => AP1W3242 ...
10
votes
5answers
42k views

Get variable from PHP to JavaScript

I want to use a PHP variable in JavaScript. How is it possible?
8
votes
3answers
299 views

Is there a way to store Arabic dates with Postgres?

I am a PHP developer and I am working on a project in which I need to store Arabic dates in my database. However, I have created the application and embedded a JavaScript Arabic calender in it. Now ...
7
votes
4answers
12k views

Pass Javascript Array -> PHP

Let's say I have a javascript array with a bunch of elements (anywhere from 50-200). I want to send that to PHP (prepared statement) using ajax. Currently, I .load a php file many times inside of a ...
7
votes
6answers
14k views

Set Session variable using javascript in PHP

Is it possible to set PHP session variables using Javascript?
7
votes
3answers
1k views

How can I combine multiple signup options facebook twitter openid

I want to build a login system with javascript and PHP, that will let users use existing accounts to login to my site. They should be able to use at least these accounts... Facebook Twitter ...
6
votes
7answers
441 views

What's the appropriate HTTP resonse for invalid data submited by the user?

I'm experimenting with JSON and http response codes. I'm submitting a form via an AJAX request and I obviously need to validate the data on the server-side. My idea is to respond with a "200 OK" ...
5
votes
8answers
14k views

Check if cookies are enabled

I am working on a page that requires javascript and sessions. I already have code to warn the user if javascript is disabled. Now, I want to handle the case where cookies are disabled, as the session ...
5
votes
5answers
11k views

How to embed php in javascript?

how can we use php in between javascript ????? like function jst() { var i = 0 ; i = <?php echo 35; ?> alert( i ); } Please suggest a better way

1 2 3 4 5 1857
15 30 50 per page