-2

I'm currently trying to implement a self hosted video player into an existing script, however the code required includes both ' and " how would I implement this into my PHP code ?

$html .= '<video id="vid1" class="video-js" controls="" preload="auto" data-setup="{}"><source src="'.$Player['URL'].'" poster="'.$Poster['URL'].'" type="video/mp4"></video>';

This works perfectly fine as is, however I'm needing this additional code implemented into the video player, but as I mentioned above it includes ' and " which makes it very difficult to implement.

data-setup='{
            "plugins": {
                    "vastClient": {
                    "adTagUrl": "AD TAG"
                }
            }}'

The main chunk of PHP cannot be rewritten as it would take far too long, I'm sure there's a solution which I'm looking over.

Any help or ideas would be fantastic thanks.

I have tried replacing ' with " which results in an error, I have also tried /' which has the same result.

  • The escape character is \`\\` not `/`, but the code above should work fine as it is. – Obsidian Age Mar 29 '22 at 23:04
  • [Using html inside double quoted echos](https://stackoverflow.com/q/55248214/2943403) Maybe worth a read: https://stackoverflow.com/q/8542746/2943403 and https://stackoverflow.com/q/15838593/2943403 – mickmackusa Mar 29 '22 at 23:11
  • TBH it looks like you should use `data-setup="' .htmlspecialchars(json_encode(['plugins' => ... ])).'"` – Phil Mar 29 '22 at 23:12
  • Good advice @Phil, I added three more dupes that demonstrate that advice. – mickmackusa Mar 29 '22 at 23:18

1 Answers1

0

Simpliest way to use both ' and ", use heredoc/nowdoc.

Joel
  • 1,187
  • 1
  • 6
  • 15
  • Multi-duplicate questions do not need new answers to resolve the page. Please help to reduce redundant content by closing pages that should be closed instead of answering them. – mickmackusa Mar 29 '22 at 23:12