Reputation: 27
How can I get php to output this correctly (with working html-iframe)? It doesn't work because the single quotation mark is already used but the double quotation mark is used too.
echo "<p data-toggle='popover' title='word' data-html='true' data-content='<iframe src='https://www.somelink.com'></iframe>'>";
(echo is php, data-toggle etc are bootstrap, data-content defines what is inside a popover)
Upvotes: 0
Views: 363
Reputation: 570
If you are using the data content for JS purposes I would store only the URL and not a full Iframe tag. This way you can use single quotes and keep everything with proper double qoutes:
echo '<p data-toggle="popover" title="word" data-html="true" data-content="https://www.somelink.com">';
then in your js just create an iframe assign the url to its source and append.
It seems like bad practice to have full markup in a data attribute and this allows you to keep cleaner code quote wise.
Upvotes: 1
Reputation: 793
Try stripslashing your string.
echo "<p data-toggle='popover' title='word' data-html='true' data-content='<iframe src=\"https://www.somelink.com\"></iframe>'>";
More information about stripslashes: http://php.net/manual/en/function.stripslashes.php
Upvotes: 2
Reputation: 76577
Consider escaping the double quotes characters that enclose your src
attribute using backslashes \"
:
echo "<p data-toggle='popover' title='word' data-html='true' data-content='<iframe src=\"https://www.somelink.com\"></iframe>'>";
Upvotes: 2