Reputation: 212
How to insert html code inside an array in PHP?
I tried searching on internet but found nothing.
$html = array
('<IFRAME src="http://link1.com" width="1" height="1"
scrolling="auto" frameborder="0"></IFRAME>' ,
'<IFRAME src="http://link2.com" width="1" height="1"
scrolling="auto" frameborder="0"></IFRAME>' ,
'<IFRAME src="http://link3.com" width="1" height="1"
scrolling="auto" frameborder="0"></IFRAME>');
print_r ($html);
When I tried to print_r
, there was no result.
Upvotes: 0
Views: 3509
Reputation: 60536
If you are printing these and accessing the output through your browser, you won't see any string as they are parsed by your browser.
If you would like to have a look at the raw output, do
echo htmlspecialchars(print_r($html, 1), ENT_QUOTES, 'UTF-8');
Upvotes: 2
Reputation: 386
I had no problem running the code you just posted. If you are outputting to a webpage the iframes are most likely there and you should just view your page source. Try this...
<?php
$html = array('<IFRAME src="http://link1.com" width="1" height="1" scrolling="auto" frameborder="0"></IFRAME>',
'<IFRAME src="http://link2.com" width="1" height="1" scrolling="auto" frameborder="0"></IFRAME>',
'<IFRAME src="http://link3.com" width="1" height="1" scrolling="auto" frameborder="0"></IFRAME>');
echo "<pre><code>";
echo print_r ($html);
echo "</code></pre>";
?>
Upvotes: 0
Reputation: 437404
There is no result because you are giving the output to the browser, which happily places three <iframe>
s with invalid source URLs in your page. So you see nothing for the same reason you would see nothing if you did print '<p></p>';
.
If you view the page source you will see your HTML is there.
Normally to see HTML markup as "plain text" you would need to pass it through htmlspecialchars
-- however, that function works with strings and here you have an array. So if you want to print the contents as human-readable text, you need to do something fancier and use array_map
:
print_r(array_map('htmlspecialchars', $html));
Upvotes: 2