logo CBCE Skill INDIA

Welcome to CBCE Skill INDIA. An ISO 9001:2015 Certified Autonomous Body | Best Quality Computer and Skills Training Provider Organization. Established Under Indian Trust Act 1882, Govt. of India. Identity No. - IV-190200628, and registered under NITI Aayog Govt. of India. Identity No. - WB/2023/0344555. Also registered under Ministry of Micro, Small & Medium Enterprises - MSME (Govt. of India). Registration Number - UDYAM-WB-06-0031863

How to call PHP file in HTML?


How to call PHP file in HTML

To call a PHP file in an HTML document, you typically embed the PHP code within the HTML file using the .php extension. Here's a simple example:

 

  1. Create a PHP File: Create a new PHP file, for example, example.php, and add some PHP code:

    <?php
    // PHP code here
    $message = "Hello from PHP!";
    ?>
  2. Create an HTML File: Create a new HTML file, for example, index.html, and include the PHP file using the include or require statement. Here's an example:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>HTML with PHP</title>
    </head>
    <body>
        <h1>Welcome to My Website</h1>
    
        <?php
        // Include the PHP file
        include('example.php');
        ?>
    
        <p><?php echo $message; ?></p>
    
        <p>This is a static HTML content.</p>
    </body>
    </html>
  3. Run the HTML File: Save both files in the same directory and run the HTML file. If you're using a local development environment like XAMPP or MAMP, place the files in the appropriate directory (e.g., htdocs for XAMPP).

    Open your web browser and navigate to the HTML file, for example, http://localhost/index.html.

  4. View Output: You should see the output of both static HTML content and the dynamic content from the PHP file.

 

In this example, the include('example.php'); statement is used to include the PHP file within the HTML file, and the PHP variable $message is echoed within the HTML content. This allows you to mix PHP and HTML seamlessly.

 

Thank you.


Give us your feedback!

Your email address will not be published. Required fields are marked *
0 Comments Write Comment