Please Login or Register to continue.


HTML is important part of website . I want to execute HTML code inside PHP code without echo. It's easy to echo HTML code but when we have lots of HTML code and want use inside PHP loop , condition or any other PHP code then it's hard to echo HTML code . I know this is very basic question of PHP but I want to know every single method to run HTML code inside PHP code without echo HTML code . How I can use HTML and CSS code inside PHP code without echo ?

(7.3K Points)
in PHP


2 Answers
(9.4K Points)

I share my experience. I was trying to create a website with HTML and CSS and I was echo block of HTML containg PHP variable . I haven't heard about that we can directly execute HTML code inside PHP after closing PHP . It was hard to echo HTML code but after that I got a solution to use HTML code inside PHP block of code . 

Yes , it's possible to execute block of HTML code inside PHP without echo any HTML block also you can place your PHP variable in HTML code .

Let's see an example 

<div class="css_class">
Variable is not set . It's your HTML code
<p>This is HTML paragraph .In this way, You can add block of code inside PHP without echo </p>



(4.3K Points)

The HTML execution process can be done by separating by PHP opening <?php and closing ?> tags . If you want to run HTML code without echo then you should separate HTML code. 

Example 1

//PHP code here 
<h2> This is HTML heading <?php echo $var; ?></h2>
//PHP code here 

You can use HTML code if you separate HTML and PHP code inside PHP tags(<?php ?> ). 

Example 2 - 

<h2>Year:-<?php echo $i;?></h2> 

Output - 


In this example, we are displaying years from 1995 to 2001 and separating HTML code without echo inside PHP code. 

HTML code can be executed by including a file. 

Create a file like - myfile.php 


<h2>This is HTML code. </h2> 
<p>This is paragraph. </p>

Now, include() file in PHP . 


In these ways , you can execute HTML code inside PHP without echo. 


Related Questions :-

Featured Items:-

Certificate system in PHP website | PHP scripts


Home Credito loan finance management multipurpose system in PHP


Result management system with Marksheet in PHP website | PHP Scripts


Your Answer

You can post your answer after login..