rustinpeace91
rustinpeace91

Reputation: 109

How can I echo the actual HTML tags with PHP?

I was thinking of maybe using PHP to automate some of the more tedious tasks of HTML while still generating a totally static page that doesn't require a back end. What I'm trying to do is simply print a large amount of <p></p> tags separated by line breaks

I've glanced at this page How to echo in PHP, html tags

Here is my code

<?php

    $t= "this is the text";

    foreach(range(1,25) as $number) {
            echo '<p>' . $t . '</p>';
            echo "</br>";

    }

?>

What it does prints two line breaks, one for the <p> tags and one for the </br> but does not actually print the <p> tags themselves, how can I get it to print the <p> and </p> tags as text and then echo a line break.

Upvotes: 2

Views: 4137

Answers (2)

Vinod Kumawat
Vinod Kumawat

Reputation: 741

USe it ,this could be work

echo "&lt;p&gt; helo &lt;/p&gt; <br>";

Upvotes: 0

Derek
Derek

Reputation: 3435

Use htmlentities to render the p tags as text.

echo htmlentities('<p>' . $t . '</p>');
echo '<br>';

Use the PHP_EOL constant to add a new line character the html ouput.

echo '<p>' . $t . '</p>';
echo PHP_EOL;

Upvotes: 6

Related Questions