PHP Introduction
PHP is a widely-used, open-source server-side scripting language for building dynamic web pages.
Syntax
<?php // your code here ?>PHP stands for PHP: Hypertext Preprocessor. It is a server-side language, which means the code runs on the web server and only the result (usually HTML) is sent to the browser.
What can PHP do?
- Generate dynamic page content.
- Collect form data and process it.
- Read, write and manage files on the server.
- Talk to databases to store and fetch information.
PHP files have the extension .php and can mix PHP code with plain text and HTML.
Example
Loading editor…
Press Run to execute the code.
When to use it
- Building dynamic web pages that change based on data or the logged-in user.
- Handling HTML form submissions and saving them to a database.
- Powering REST APIs and backends for JavaScript front-ends.
More examples
Your first script
Code between <?php ?> runs on the server; everything else is sent to the browser as-is.
<?php
echo "Hello, World!";PHP mixed into HTML
You can drop small PHP blocks anywhere inside an HTML page.
<h1><?php echo "Welcome"; ?></h1>
<p>Static HTML here.</p>Show runtime info
Built-in functions like phpversion() and date() return information at run time.
<?php
echo "PHP " . phpversion() . "\n";
echo "Today: " . date("Y-m-d");
Discussion