Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises


PHP


Server-side code.

Normally in public_html
Normally named like: file.php

File contains normal HTML, and PHP code mixed in, delimited as follows:

<html>
<body>

html code

<?php 
php code 
?>

more html code





Basics




Environment




Example PHP pages

  1. PHP demo

  2. Return a single environment variable:


Debugging

  

Dump variables




Multi-line string

A multi-line string can be useful. Assign a chunk of HTML to a string, and maybe re-use it in different places.

Strings in PHP shows ways of doing a multi-line string:


  1. Let quote run over:

     
    $var = "  
    text
    text "; 
    

    Advantages: Simple syntax.
    Disadvantages: All double quotes in the text must be changed to single quotes or else "escaped". Can't just dump HTML in here.


  2. Use a heredoc:

     
    $var = <<<MULTILINE_DELIMITER
    text
    text 
    MULTILINE_DELIMITER;
    

    Advantages: Can have single and double quotes in the text unchanged. Can just dump HTML in here.
    Disadvantages: Complex syntax.




Reference

  

Tutorials



Search php.net: with Google.



ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.