/    Sign up×
Community /Pin to ProfileBookmark

Printf And Mobile Responsive iFrame

Folks,

Look at this Mobile Responsive iFrame:

““
<!DOCTYPE html>
<html>
<head>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<style>
.container {
position: relative;
width: 100%;
overflow: hidden;
padding-top: 56.25%; /* 16:9 Aspect Ratio */
}

.responsive-iframe {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
border: none;
}
</style>
</head>
<body>

<h2>Responsive Iframe</h2>
<h3>Maintain Aspect Ratio 16:9</h3>
<p>Resize the window to see the effect.</p>

<div class=”container”>
<iframe class=”responsive-iframe” src=”https://www.youtube.com/embed/tgbNymZ7vqY”></iframe>
</div>

</body>
</html>
““

https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_responsive_iframe_169

Now, I need to secure it with htmlentities & urlencode and the like where necessary before echoing the iFrame to open to users (for security purpose).
I tried this:

““
$url = $_SESSION[‘url’];
printf(“<div class=’container’><iframe class=’responsive-iframe’ src=’%s’ height=’100%’ width=’100%’></iframe></div>”,
htmlentities($url)
);
““

Get error:
Warning: printf(): Too few arguments in C:xampphtdocstestdoorpage.php on line 25

I reckon these are causing the issue: height=’100%’ width=’100%.
Q1. How to fix ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 19.2020 — Escape the literal percent characters with another percent character in the string, e.g. height='100%%' width='100%%'.
Copy linkTweet thisAlerts:
@developer_webauthorNov 19.2020 — @NogDog#1625206

Thanks.

Now, do I use htmentities() or urlencode() here ? Or both ?

Example 1:

printf( "<iframe src='%s'></iframe><br>", htmlentities($url));


Example 2:

printf( "<iframe src='%s'></iframe><br>", urlencode($url));


Example 3:

printf( "<iframe src='%s?tbl=%s&col=%s&search=%s&limit=%d&page=%d'></iframe><br>", htmlentities($url), urlencode($url));
Copy linkTweet thisAlerts:
@developer_webauthorNov 19.2020 — Folks,

Notice the html of both examples. Which should I use ?

1

printf("<div class='container'><iframe class='responsive-iframe' src='%s' height='100%%' width='100%%'></iframe></div>",
htmlentities($url)
);


2

<div class='container'>
<?php
printf("<iframe class='responsive-iframe' src='%s' height='100%%' width='100%%'></iframe>",
htmlentities($url)
);
?>
</div>


Or, can you better it ?
Copy linkTweet thisAlerts:
@developer_webauthorDec 03.2020 — @NogDog

Care to chime in ?

Thanks!
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...