using php in html file code example

Example 1: load php in html

//Safe as:
index.html
number.php

//HTML:
<html>
   <head>
      <title>Home</title>
   </head>
   <body>
      <h1>Phone Number</h1>
      <?php include('number.php') ?>
   </body>
</html>

//PHP:
<?php
   echo 4895553268;
?>

Example 2: .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!!!!!

Tags:

Php Example