PHP Embed a HTML Tag (that has double & single quote marks) into a PHP echo statement.

I am trying to customize a HTML template (Porto from ThemeForrest).

For simplicity, I've only included the single line of HTML that's causing the problem:

<?php echo '
<div class="slider" id="revolutionSlider" data-plugin-revolution-slider data-plugin-options=\'{"startheight": 500}\'>
' ?>

Open in new window

I've tried escaping the single quotes inside the echo statement but that breaks the slider.

Does anyone have a work-around for this?   OR
Is there another way I can encapsulate the HTML so that it can be used on multiple pages using the PHP Include statement?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
you can try:

<?php echo "<div class='slider' id='revolutionSlider' data-plugin-revolution-slider data-plugin-options='{\"startheight\":500}'>" ?>
GrahamPoleAuthor Commented:
Thanks Ryan... This still breaks the Slider!
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
what about this?

<?php echo "<div class=\"slider\" id=\"revolutionSlider\" data-plugin-revolution-slider data-plugin-options='{\"startheight\": 500}'>" ?>
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Dave BaldwinFixer of ProblemsCommented:
Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<title>PHP Quote test</title>
<h1>PHP Quote test</h1>
$echostr = <<<EOS
<div class="slider" id="revolutionSlider" data-plugin-revolution-slider data-plugin-options='{"startheight": 500}'>
echo $echostr;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GrahamPoleAuthor Commented:
Hi Dave,

Your suggestion solved my problem.

GrahamPoleAuthor Commented:
Hi Ryan,

Thanks again for your suggestion... I had tried that strategy before posting the original question. Unfortunately, escaping any of the quotes results in breaking the slider...

<?php echo "<div class=\"slider\" id=\"revolutionSlider\" data-plugin-revolution-slider data-plugin-options='{\"startheight\": 500}'>" ?>"

Open in new window

The above strategy breaks the slider.

Dave Baldwin came up with a solution... See above post.

Ray PaseurCommented:
For a deeper understanding of how quotes work in PHP, we have this article:

Going forward, you can post your future questions in more than one "Zone" so if there is something like WordPress involved, you can add the WordPress Zone, HTML Zone, etc.  This may get more eyes on the questions.  Just a thought...
Dave BaldwinFixer of ProblemsCommented:
Graham, please close out this question by accepting my comment above as the solution and awarding points to me for it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.