Basic Syntax of PHP: Getting Started with PHP Programming

Rumman Ansari   Software Engineer   2024-07-09 10:01:44   5719  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

You can run PHP code on any web browser. The PHP script is executed on the server, and the plain HTML result is sent back to the browser.

Basic Syntax of PHP

  • PHP code is start with  <?php  and ends with  ?>
  • Every PHP statements end with a semicolon (;).
  • PHP code save with .php extension.
  • PHP contains some HTML tag and PHP code.
  • You can place PHP code anywhere in your document.

PHP Syntax

<span class="pln">

</span><span class="pun">&lt;?</span><span class="pln">php
</span><span class="com">// PHP code goes here</span><span class="pln">
</span><span class="pun">?&gt;</span><span class="pln">

</span>

PHP files save with .php extension and it contain some HTML and PHP code.

<span class="pln">
</span><span class="dec">&lt;!DOCTYPE html&gt;</span><span class="pln">
</span><span class="tag">&lt;html&gt;</span><span class="pln">
</span><span class="tag">&lt;body&gt;</span><span class="pln">

</span><span class="tag">&lt;h1&gt;</span><span class="pln">This is my first PHP code</span><span class="tag">&lt;/h1&gt;</span><span class="pln">

</span><span class="pun">&lt;?</span><span class="pln">php
echo </span><span class="str">"Hello World!"</span><span class="pun">;</span><span class="pln">
</span><span class="pun">?&gt;</span><span class="pln">

</span><span class="tag">&lt;/body&gt;</span><span class="pln">
</span><span class="tag">&lt;/html&gt;</span><span class="pln">

</span>

Output

	
This is my first PHP code

No Questions Data Available.
No Program Data.

Stay Ahead of the Curve! Check out these trending topics and sharpen your skills.