-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.

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

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.