• Skip to main content
  • Skip to primary sidebar
  • Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / tutorials / Php tutorials / how to write html in php

how to write html in php

write html in php

 

Table of Contents

Toggle
  • write html in php variable
  • 2nd way write html in function & use function as variable
  • write html in php function
  • inside of php include html using echo  or print
  • HTML executes automatically by php interpreter outside of php
  • Does html tags executes anywhere in php

write html in php variable

<?php
$my_var = <<<EOD
<div>SOME HTML</div>
EOD;
?>
echo $my_var;
<p><?php echo $VAR; ?></p>   //php inside html
heredoc
<?php
echo <<<GFG
    html markup
hh
j
GFG;
?>

2nd way write html in function & use function as variable

?phpfunction htmlContent(){
?>
    <h1>Html Content</h1>
<?php
}
?>
$var = htmlContent();
$title = ‘<a class=”title” href=”‘ . apply_filters( ‘the_permalink’, get_permalink() ) . ‘”>’ . get_the_title() . ‘</a>’;
$title =  ‘<a class=”title” href=”https://google.com”>’ . hyperlinktext . ‘</a>’ ;
$title = ‘<h2>’. ‘<a class=”title” href=”https://google.com”>’ . hyperlinktext . ‘</a>’ . ‘</h2>’;
. means concatenate in php
practice at w3school php

write html in php function

<?php
function writeMsg() {
  echo “Hello world!”;
}
writeMsg(); // call the function
?>

inside of php include html using echo  or print

<?php
Echo “<html>”;
Echo
“<title>HTML With PHP</title>”;
Echo
“<b>My Example</b>”;
//your php code here
Print
“<i>Print works too!</i>”;
?>

HTML executes automatically by php interpreter outside of php

<html>
<title>HTML with PHP</title>
<body>
<h1>My Example</h1>
<?php
//your PHP code goes here
?>
<b>Here is some more HTML</b>
<?php
//more PHP code
?>
</body>
</html>

Does html tags executes anywhere in php

no;
with echo or print command
<!DOCTYPE html>
<html>
<body>
<?php
function writeMsg() {
  echo “Hello world!”;
}
$var=title;
writeMsg();
echo “</br>”;
echo $var;
?>
</body>
</html>
Hello world!
title

Primary Sidebar

tutorials

  • Core Java Tutorial Free online
  • HTML & CSS Tutorials
  • Php tutorials
    • OPcache enable / configuration settings purge wordpress nginx php-fpm ubuntu (How to enable)
    • PHP performance tuning nginx php-fpm conf pool manger dynamic vs static vs on demand
    • how to write html in php
  • ubuntu tutorials installation download issues etc
  • redis install ubuntu 20.04 with wordpress php redis mysql configuration
  • [INTRO] Ethical hacking / cyber Security / Penetration testing Tutorial -{updates frequently}
  • Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment
  • AUdio Editing Background Noise removal (Audacity, Adobe Premiere Addition, Camtasia Filmora Windows Obs)
  • what is vpn vs proxy vs tor, http vs https, http2, tcp vs udp, kali linux sql source code injection
  • how to create a website free of cost on google
  • CCNA Syllabus pdf (CCNA / CCNP vs devops vs mcsa /MCSE)
  • Redis performance metrics & tuning for nginx apache ubuntu & debian
  • xampp tutorials 2021 installation errors fix wordpress phpmyadmin mysql apache
  • new relic installation linux (infrastructure agent , php, mysql , nginx)
  • new relic mysql install integration - 2 ways fix problems
  • new relic php agent install in 3 steps
  • aws load balancer tutorial
  • git branches merge fetch pull conflicts

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy