"Welcome to our PHP 101 blog, where we demystify the world of web development. "

Sunday, June 17, 2018

HTML in PHP


Do You Want to add HTML to a PHP file?
HTML and PHP are two separate programming languages, but you might use both of them on the same page to take advantage of what they both offer.
With one or both of these methods, you can easily embed HTML code in your PHP pages, to format them better and make them more user-friendly. The method you choose depends on your criteria of your situation.
i)By Using HTML tags
Your first option is to build the page like a normal HTML web page with HTML tags, inside the html tags you can  use separate PHP tags to wrap up the PHP code.
You can even put the PHP code in the middle  <?php and ?>tags.
Syntax:
<?php
php stattements;
?>
 This method is especially useful if you have a lot of HTML code but want to also include PHP.
Examples:
<html>
<title>Html with PHP</title>
<body>
<h1>PHP WITH HTML EXAMPLE</h1>
<?php //Your PHP code
?>
<h1>Some  More HTML</h1>
<?php //Your PHP code
?>
</body>
</html>
ii)Use PRINT or ECHO
This  is the basically the opposite; it's the way in which  you  add HTML to a PHP file with PRINT or ECHO, where either command is used to simply print HTML on the page.
With this method, you can include the HTML inside of the PHP tags.
This is a good method to use for adding HTML to PHP if you only have a line or so to do.
Example:
<?php
echo “<html>”;
echo “<title>HTML With PHP</title>”;
echo “<b>Example</b>”;
//php statements
print “<i> Print als works here</i>”;
?>


No comments:

Post a Comment

Pages

SoraTemplates

Best Free and Premium Blogger Templates Provider.

Buy This Template