php file syntax code example
Example 1: php hello world
echo "Hello World";
Example 2: php in html
Basic PHP Syntax
A PHP script can be placed anywhere in the document.
A PHP script starts with <?php and ends with ?>:
<?php
?>
The default file extension for PHP files is ".php".
A PHP file normally contains HTML tags, and some PHP scripting code.
Example
<!DOCTYPE html>
<html>
<body>
<h1>Php in html</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
Example 3: .php file
<html>
<head>
<title>Reading a file using PHP</title>
</head>
<body>
<?php
$filename = "abc.txt";
$file = fopen( $filename, "r" );
if( $file == false ) {
echo ( "Error in opening file" );
exit();
}
$filesize = filesize( $filename );
$filetext = fread( $file, $filesize );
fclose( $file );
echo ( "File size : $filesize bytes" );
echo ( "<pre>$filetext</pre>" );
?>
</body>
</html>
//This is a php File Yes!!!!!