Php Syntax

Php is a scripting language and it is used to create dynamic webpages. It is very easy to learn. Now times more than 70% of websites are built in PHP. every PHP file has .php extension.

Syntax:-


<?php 

?>

Example:- you have to print Hello Php


<?php 
print 'Hello Php';
?>
Hello Php

Try it on PHP Editor

HTML Embedding in php file

You can embedded html code into PHP file


<HTML>
<HEAD> 
This is a sample. 
</HEAD>
<BODY>
Hello techfliez.com
<?php 
print "Hi, how are you?";
?>
</BODY>
</HTML>

How to enable PHP short tag?

You can enable php short tag through php.ini file. firstly open the php.ini file after that short_open_tag=on.


short_open_tag=on

Now, write the PHP code

Syntax:-


<?

?>

Example:- you have to print Hello Friends


<?
print 'Hello Friends';
?>
Hello Friends

Php Syntax – Interview Questions

Q 1: How does a PHP script start and end?
Ans: PHP scripts start with .
Q 2: Is semicolon mandatory in PHP?
Ans: Yes, each PHP statement must end with a semicolon.
Q 3: Is PHP case-sensitive?
Ans: Variable names are case-sensitive, but keywords are not.
Q 4: Can PHP be embedded in HTML?
Ans: Yes, PHP code can be written inside HTML.
Q 5: What is the use of echo in PHP?
Ans: echo is used to output data to the browser.

Php Syntax – Objective Questions (MCQs)

Q1. PHP statements end with ______.






Q2. PHP code starts with ______.






Q3. PHP variables start with ______.






Q4. Which is correct syntax to print text in PHP?






Q5. PHP is ______ case sensitive.






Related Php Syntax Topics