Export (0) Print
Expand All

Insert a PHP script

A PHP script starts with <?php and ends with ?>. A PHP script block can appear anywhere in a PHP file. In Microsoft Expression Web, you can quickly insert commonly used PHP code snippets into your page by clicking PHP Script on the Insert menu. You can then customize those scripts to meet your needs.

For more information about PHP, see the PHP Tutorial on the W3 Schools website.

To insert a PHP script

  • On the Insert menu, point to PHP Script, and then click one of the following:

    Form Variable

    Inserts the following code block:

    <?php $_POST[]; ?>

    The $_POST method is used to collect information from a form when the information is sent using the HTTP post method (method="post").

    For more information about PHP forms, see PHP Forms and User Input on the W3 Schools website. For more information about the POST variable, see $_POST on the W3 Schools website.

    URL Variable

    Inserts the following code block:

    <?php $_GET[]; ?>

    The $_GET method is used to collect information from a form when the information is sent using the HTTP GET method (method="get"). Information collected using the GET method is displayed in the URL.

    For more information about PHP forms, see PHP Forms and User Input on the W3 Schools website. For more information about the GET variable, see $_GET on the W3 Schools website.

    Session Variable

    Inserts the following code block:

    <?php $_SESSION[]; ?>

    A session is the amount of time that an individual user spends at your website. By using a session variable, you can save information and make that information available to other pages that the user visits in the same session.

    For more information about PHP sessions, see PHP Sessions on the W3 Schools website.

    Cookie Variable

    Inserts the following code block:

    <?php $_COOKIE[]; ?>

    A cookie is a small file that is saved to the visitor's computer by the server in order to identify the computer. The PHP $_COOKIE variable is used to retrieve a cookie value from the computer.

    For more information about PHP cookies, see PHP Cookies on the W3 Schools website.

    Include

    Inserts the following code block:

    <?php include(); ?>

    You can insert a file into a page by using an include statement. When using an include statement, the included file is retrieved and then displayed in the page when the page is requested from the server. The include statement is similar to a require statement, except that the include statement does not require the successful execution of the script in order to display the page.

    For more information about PHP include files and the include() function, see PHP Include Files on the W3 Schools website.

    For more information on using PHP includes in Expression Web, see Include a file in a PHP page.

    Require

    Inserts the following code block:

    <?php require(); ?>

    You can insert a file into a page by using a require statement. Like the include statement, the included file is retrieved and then displayed in the page when the page is requested from the server. However, unlike the include statement, a require statement requires the successful execution of the script in order to display the page.

    For more information about PHP include files and the require() function, see PHP Include Files on the W3 Schools website.

    Code Block

    Inserts the following code block:

    <?php ?>

    PHP scripts begin with <?php and end with ?>. Any text typed between the start and end script tags will be interpreted as PHP scripting.

    For more information about PHP, see the PHP Tutorial on the W3 Schools website.

    Echo

    Inserts the following code block:

    <?php echo ?>

    Echo statements are displayed as HTML in the browser. For example, the statement <?php echo "<p>Hello World</p>"?> appears as <p>Hello World</p> in the source code of the page, and is displayed as Hello World in the browser.

    For more information about echo statement, see PHP Syntax on the W3 Schools website.

    Comment

    Inserts the following code block:

    /* */

    PHP comments begin with /* and end with */. Any text typed between the start tag and the end tag of the comment will not be displayed in the browser.

    For more information about PHP comments, see PHP Syntax on the W3 Schools website.

    If

    Inserts the following code block:

    <?php if ?>

    An if statement checks whether certain conditions exist. An if statement is usually followed by a statement or series of statements. If the condition is true, the statements following the if statement are executed. If the condition is false, the statements following the if statement are not executed.

    For more information about PHP if statements, see PHP If…Else Statements on the W3 Schools website.

    Else

    Inserts the following code block:

    <?php else ?>

    An else statement is optional when using an if statement. Like the if statement, an else statement is usually followed by a statement or series of statements to be executed. An else statement is only executed if the condition for the if statement preceding it is false.

    For more information about PHP else statements, see PHP If…Else Statements on the W3 Schools website.

Community Additions

ADD
Show:
© 2014 Microsoft