Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9497

Re: Problem with quotes in javascript output

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.php
Subject Re: Problem with quotes in javascript output
Date 2013-05-21 10:47 +0000
Organization A noiseless patient Spider
Message-ID <knfjcj$e55$1@dont-email.me> (permalink)
References <54lw0fd343qv$.gm5ydjjd60j9$.dlg@40tude.net>

Show all headers | View raw


On Mon, 20 May 2013 12:17:26 -0400, richard wrote:

> This is not a javascript question ok?

Actually it is, because the problem seems to be that you're producing 
invalid javascipt.

> The problem mainly deals with required quotes in the javascript output.
> Either single or double.

I don't think it does, although I suspect they may be an issue.

As far as I can tell, the final argument to jwplayer("my-video").setup() 
looks like this (I've added some spaces for readability):

{ playlist : [ { { file : "http://www.youtube.com/watch?v=$vid[2]", 
description : "$year # $number - $vid[1]" } ], "startparam" : "start", 
"repeat" : "list", "width" : 800, listbar : { position : 'right', size : 
320}, "height" : 450 }

There are several things here that might cause problems:

1) Mismatched brackets. You don't have the same number of all of (, { and 
[ as you do respectively of ), } and ]. This is probably breaking the 
javascript.

2) Some attributes are quoted and others are not. Although javascript is 
fairly tolerant as to which quotes you use in that it generally treats 
single and double quoted strings identically, I suspect that either you 
should be passing either strings for all the attributes, or names for all 
the attributes, but not a mixture of strings and names. For example, 
playlist, file, description, listbar, position and size are names; and 
"startparam", "repeat", "width" and "height" are strings. This may be 
breaking the javascript.

3) Your php variable substitution isn't going to work for two reasons. 
You need something more like:

echo "file: 'http://www.youtube.com/watch?v={$vid[2]}'";
echo ",";
echo "description: '$year # $number - {$vid[1]}'";

or

echo "file: \"http://www.youtube.com/watch?v={$vid[2]}\"";
echo ",";
echo "description: \"$year # $number - {$vid[1]}\"";

This is to address that (a) php variable substitution only works in 
double quoted strings (ie when using "" and not ''), and (b) you should 
wrap constructs of $array[element] with {} when using variable 
substitution. This is probably causing the data passed to the javascript 
to not be what you think it's getting.

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Problem with quotes in javascript output richard <noreply@example.com> - 2013-05-20 12:17 -0400
  Re: Problem with quotes in javascript output Jerry Stuckle <jstucklex@attglobal.net> - 2013-05-20 12:53 -0400
  Re: Problem with quotes in javascript output richard <noreply@example.com> - 2013-05-20 14:12 -0400
  Re: Problem with quotes in javascript output Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-21 10:47 +0000
    Re: Problem with quotes in javascript output Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-21 13:59 +0200

csiph-web