Embed PHP in HTML
PHP & MySQL Course:Embed PHP in HTML
In the previous lecture 6, we learnt about the functions as there are built-in and user-defined functions in very
programming language. We also discussed the sorting arrays PHP, and used built-in functions of PHP
programming to sort the arrays in an easy.
Lecture 7:Embed PHP in HTML
In this lecture we will study, how we can use the HTML tags in PHP programming. And we need sometimes to
use the HTML tags in PHP programming. Following are the topics of lecture 6.
- HTML tags in PHP
- Concatenation operator in PHP
- Use of variables in PHP with display functions
HTML tags in PHP:
There are many tags in HTML which we can use them in PHP programming. By using of them we feel easy
to designvdynamic web pages. We use commonly tags of HTML in PHP programming as there are heading
tags, break tag etc. Check the listing 1 for details about the HTML tags in PHP. There is an example in the
listing 1, from which you will understand how you can use the HTML tags in PHP.
Listing 1: Use of HTML tags in PHP
//using the html table tag in PHP to create a table <?php echo " <h1>HTML tags in PHP...</h1>" ; ?>
Concatenation Operator in PHP:
We use dot operator as a concatenation operator in PHP. Due to dot operator we can join any two strings.
And we use it during the display of variables. At that time we use dot operator to display the data of the
variable in echo or print function. We can also display the data of the variables in PHP if we use the
variable of the PHP inside the double quotes. For details about the concatenation check the listing 2.
There is a simple example from which you will learn how you can use dot operator. And you
will be able to understand where you should use the dot operator.
Listing 2: Concatenation Operator in PHP
<?php //use of dot operator in PHP $name1 = "Trust"; $name2 = "In"; $name3 = "Geeks"; $FullName = $name1.$name2.$name3; echo $FullName; //an other way to use dot operator in PHP echo "The Full name of the website is: ".$name1.$name2.$name3; ?>php
Use of variable in PHP:
There is a way how to use the variables in PHP. As we commonly declare the variables and assign them values.
After that we use them in the program for more process. But we can use them to declare, assign and use them
for any process at the same time. Check the listing 3 for details about the variable uses in PHP programming.
You will see something new to learn about the PHP variables.
Listing 3: Variable use in PHP<?php //using variables in PHP with dot operator $name = "TrustInGeeks"; echo "My Website Name is: ".$name; print "My Website Name is: ".$name; //using variables in PHP without dot operator //we will use variables in PHP inside the double quote echo "My Website Name is: $name"; print "My Website Name is: $name"; ?>php
In this lecture we learnt something important about the use of variables and dot operator in PHP.
Form using of the dot operator in PHP I shown you how you can concatenate the two different
strings in PHP. We also discussed the HTML tags, we can use all HTML tags in the PHP programming.
And there is no any kind of violation in PHP to avoid the HTML tags. We can use them without