I am hoping someone can help me. I have a variable in PHP that I need to use in a bash script. That string in the variable needs to be transformed to a specific format to wrap every word in the string in double quote and backslash.
Here is it specifically:
$raw = "amazon,facebook,reddit";
The output of the desired function needs to look like this:
\"amazon\",\"facebook\",\"reddit\"
Obviously the $raw variable could hold more or less words separated by comma.
The best I could do using str_replace is this:
$trfm = '"' . str_replace(",", "\",\"", $raw) . '"';
echo $trfm;
"amazon","facebook","reddit"
so I need to figure out how to add the backslashes.
Thanks