Link to home
Start Free TrialLog in
Avatar of GrahamPole
GrahamPoleFlag for Australia

asked on

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:

Example:
<?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?

Thanks
Graham
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

you can try:

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

ASKER

Thanks Ryan... This still breaks the Slider!
what about this?

<?php echo "<div class=\"slider\" id=\"revolutionSlider\" data-plugin-revolution-slider data-plugin-options='{\"startheight\": 500}'>" ?>
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Dave,

Your suggestion solved my problem.


Thanks,
Graham
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.

Thanks
Graham
For a deeper understanding of how quotes work in PHP, we have this article:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html

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...
Graham, please close out this question by accepting my comment above as the solution and awarding points to me for it.