HTML - 包含php [关闭]

For example i can import javascript:

<script src="script.js"/>

or include:<script>//some script</script>

I can import php like this:

<form action="file.php">

But how to include it?

I mean not to create additional php file.

Like this <form action=<?php /*php there*/ ?>>

Thanks!

An HTML file cannot include a php file in the sense you're asking, because a .php file is being processed by the server and is (generally) outputting HTML.

Your example...

I can import php like this:

<form action="file.php">

is not "importing" php, it is directing the form POST to a php file to be processed, which then outputs HTML as its response.

In general, when doing PHP programming, you are writing .php files instead of writing .html files. If something needs to use PHP code it should be in a .php file, not a .html file which normally has completely static content.

There is a way to have your PHP processor act upon .html files, and that is to configure Apache (or whatever your webserver is) to hand .html files to PHP in the same way it is configured to handle .php files — but then you are incurring the overhead of processing every .html file whether or not it actually has PHP code in it.

<?php include "file-name.php" ?>

Make sure you are having .php etension for your file

  <?php include "filename.php" ?>

Here are the different ways of including a php file.

<?php include 'file.php';?>
//OR
<?php include_once 'file.php';?>
//OR
<?php require('file.php');
//OR
<?php require_once('file.php');

 looking at your code,  you are trying to set a file in the action attribute
 of a form.  If that is true then you do not need to include the file. 
 On form submission the script in the action will be executed.