
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use PHP in HTML
To use PHP in HTML, you must enclose the PHP code with PHP start tag <? php and end tag ?>. In this article from the example we will learn to use and become comfortable with PHP in HTML.
PHP (Hypertext Preprocessor) is a popular server-side scripting language used for web development. It allows you to embed dynamic content into your HTML.
Approach to use PHP in HTML
To effectively use PHP in HTML, you need to enclose PHP code within <?php
and ?>
tags. Remember, PHP files must have a .php
extension since PHP code is processed on the server before the page is delivered to the client.
Let's see some examples so you will be comfortable using PHP in HTML.
Example 1
In this example, we are rendering a simple h2 tag with PHP code.
<!DOCTYPE html> <html> <body> <h2> <?php echo "Welcome to PHP" ?> </h2> </body> </html>
Example 2
In this example we are using different php code snippets to understand the concept properly. In the below example we are using tags like <p>, for aligning the text in paragraph format. <strong>tag for making the text bold.<center> to align the text to the center.
<!DOCTYPE html><html> <body> <center> <p> <?php echo "This is php webpage,hello <strong>everyone</strong>" ?> <br><br> <?php echo 'Learn php easily.' ?> </p> </center> </body> </html>
Conclusion
In this way you can use different tags in PHP to customize your text and also different things can be made with the use of PHP in HTML.