Karl B's answer is better - use it!
It would not be easier:
$var = "hello,world,test"; $var = str_replace(",", "','", $var);
Then wherever you spit out JavaScript (assuming you can use PHP there):
var name = ['<?php echo $var; ?>'];
This does not apply to quotation marks, but if you want it, you better use fgetscsv et et al.
If you intend to use explode , you can use the other half, implode , like this in your output:
var name = ['<? php echo implode("','", $var); ?>'];
source share