Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Basics (Retired) PHP Datatypes Strings

Derek Dawes
Derek Dawes
4,944 Points

<pre> before <?php? Whats the purpose?

I understand the purpose of <pre> </pre> in html to display text. But whats the purpose of using it before php code?

I.e.

<pre>
<?php
$one = 1;
$two = 2;
echo $two;
?>
</pre> etc. etc. ....

Thanks

3 Answers

Jacobus Hindson
Jacobus Hindson
14,429 Points

Derek,

The tag literally is HTML at that point because it is called before the php code. As your php code uses echo it will display the results. So the <pre> tag will use Pre-formatted HTML to display them.

In simple words i'll say it helps keep the original format of the text you are trying to display. Which means keeping the white spaces, line breaks etc. It is an HTML tag as Jacobus Hindson stated earlier. You can see an example of how it works here - html - <pre> preformatting

Try it with... Then try it without. Which one is easier to read? :-)