使用javascript在PHP echo中使用3个时间引号

Iam trying to execute a script with PHP and there I got a Problem with the Quotes. How do I do, if I need 3 times Quotes in ONE String? Here my Prob:

echo "
  <script>
     $('input[name=plattformStreamer1][value='youtube']').prop('checked',true);
  </script>
";

I have in PHP at the beginning the Double-Quotes to open the echo. After that I use the Single Quotes for the jQuery Selection and than I use them also in the Selector. I feel kinda stupid that I get no Solution :D

Thanks for help :)

you can escape those string with backslash, or use heredoc

echo <<<EOL
  <script>
     $("input[name=plattformStreamer1][value='youtube']").prop('checked',true);
  </script>
EOL;

Use backslash

echo "
  <script>
     $('input[name=plattformStreamer1][value=\'youtube\']').prop('checked',true);
  </script>
";

Simplest solution is to drop out of PHP to output the JS code.

?>
  <script>
     $(input[name=plattformStreamer1][value='youtube']).prop('checked',true);
  </script>
<?php

All the other answer will work as well but I like to use sprintf or vsprintf if you are building html a lot in PHP and then outputting it. Basically you can build up your parameters and then pass them to what you want them to look like.

sprintf you have to set each param as an argument. It can be direct but I used variables.

//You can parameter your html
$value = "youtube";
$prop = "checked";

$input = sprintf("<script>$(input[name=plattformStreamer1][value='%s']).prop('%s',true); </script>",$value,$prop);

echo $input;

vsprintf acts the same but takes an array:

$arr = ["youtube","checked"];

$input = vsprintf("script>$(input[name=plattformStreamer1 [value='%s']).prop('%s',true); </script>",$arr);

echo $input;