Introduction

Transitioning to PHP from NetCloak.

NetCloak

NetCloak provides web-masters with a simple yet powerful set of commands for creating dynamic websites. Maxum developed NetCloak for use with servers running on the MacOS.

NetCloak commands are embedded into HTML documents with a syntax similar to HTML tags. When an HTML document is requested from a web server running NetCloak, the server allows NetCloak to review the file before sending it to the requestor. NetCloak executes the commands and creates a fresh dynamic HTML document. The server sends the new document to the requestor.

An example: <INSERT_TIME> would print the current time: 2:27:03 AM.

Links


PHP

PHP is a freely distributed server-side parsing engine with an extremely powerful yet complex set of commands. PHP syntax is similar to C and Perl but it is embedded into HTML documents. When a PHP document is requested, the server sends the document through the PHP engine to execute the commands before returning the dynamic content.

Links

Example

Say you have a PHP file "add.php" which contains:

<FONT size="+2">
<?php
    $a = 2;
    $b = 2;
    echo "$a + $b = " . ($a + $b);
?>
</FONT>

When the file is requested, since the extension is .php, the server sends it through the PHP4 Hypertext Preprocessor. (For PHP3, the .php3 extension should be used.) The preprocessor parses the code inside the PHP tags and returns an HTML document. The resulting HTML document for this example looks like this:

<FONT size="+2">
2 + 2 = 4
</FONT>

And the view from your browser is: 2 + 2 = 4

The PHP Code

The file "add.php" contains 7 lines:
1: <FONT size="+2">
2: <?php
3:     $a = 2;
4:     $b = 2;
5:     echo "$a + $b = " . ($a + $b);
6: ?>
7: </FONT>

The <FONT> and </FONT> tags are standard HTML entities. These remain uneffected by the PHP parsing engine.

The <?php ?> tag signifies both the beginning and the end of PHP code. Inside the PHP code tag, there are 3 statements:

$a = 2;

$b = 2;

echo "$a + $b = " . ($a + $b);

The if Command

The most basic command used in PHP is the if command. The syntax is fairly straitforward.
<?php
    if( boolean_expression )
    {
        statement_1;
        statement_2;
        ...
    }
?>
boolean_expression is any PHP expression which returns a true/false value. For example, 1 == 1 returns true, whereas 1 == 2 returns false.
Operator Meaning Example: trueExample: false
== equals 1 == 1 1 == 2
!= unequal to 1 != 2 1 != 1
< less than 1 < 2 1 < 1
<= less than or equal to 1 <= 1 2 <= 1
> greater than 2 > 1 1 > 1
>= greater than or equal to 1 >= 1 1 >= 2
PHP4 defines two additional
Comparison Operators.

The if, else if, else Command

The if can be appended with the else if and else commands.
<?php
    if( boolean_expression )
    {
        statement_1;
        statement_2;
        ...
    }
    else if( boolean_expression )
    {
        ...
    }
    else if( boolean_expression )
    {
        ...
    }
    ...
    else
    {
        ...
    }
?>
You may have as many else if statements as you would like, but there is exactly one if and at most one else. Within the curly brackets, you may have as many statements as you require. Without curly brackets, you may have exactly one statement:
<?php
    if( boolean_expression )
        statement;
    else if( boolean_expression )
        statement;
    else
    {
        statement_1;
        statement_2;
        ...
    }
?>

There is also an Alternative Sytnax for Control Structures. The rest of this documentation will use the syntax described above. If you're curious, take a look at some of the other Control Structures defined in PHP.

Displaying HTML based on the if Statement

So far, we have seen that the if statement lets you specify PHP commands based on a boolean expression. If you have HTML that you want to display based on that expression you could use the echo command. But if you have a large amount of HTML, you wouldn't want to use echo, you could just leave the PHP parsing engine: the HTML would be put directly into the output.
<?php
    if( boolean_expression )
    {        // Exit the PHP and start displaying HTML.
    ?>
    
    This HTML is only displayed if <CODE>boolean_expression</CODE> is true.
    
  	<?php    // Re-Enter the PHP to finish the if statement.
  	}
?>

Discussion

Before the first line of PHP, the page is set up for either case: Welcome to the store.

<?php if( Business_Hours ) { ?>

  • <?php
  • Opens the PHP.
  • if( Business_Hours ) {
  • Business_Hours is psuedo code for a boolean expression saying that the current time is during business hours.
    Executes a sequence of commands if Business_Hours is true.
    The curly bracket is neccessary since the PHP is being closed.
  • ?>
  • Closes the PHP.
    The HTML that follows is only written if the if statement succeeded.

    <?php } else { ?>

  • <?php
  • Reopens the PHP.
  • }
  • Closes the if statement.
  • else {
  • Executes a sequence of commands if the if statement failed.
  • ?>
  • Closes the PHP.
    The HTML that follows is only written if Business_Hours was false.

    <?php } ?>

  • <?php
  • Reopens the PHP.
  • }
  • Closes the else statement.
  • ?>
  • Closes the PHP.
    The HTML that follows is always written.

    Transitioning from NetCloak to PHP

    The functionality of NetCloak is not built into PHP. To give PHP the NetCloak behavior, special functions have been defined in these files:

    NetCloak.inc contains every function.

    If you only need to use certian topics of NetCloak, include the following.

    NetCloak commands rely on commands such as <SHOW> and <HIDE> to determine which information a page will display. PHP uses the C/Perl style if command to determine such information.

    In Net Cloak you would use <HIDE><SHOW_CLIENT "Mac">to show this text to Mac users and <SHOW>to show this text to everyone.

    In PHP, if the function ClientType.inc is included then <?php if( ShowClient("Mac") ) { ?> this text will be shown to Mac users an><?php } ?> this text will be shown to everyone.

    The functionality described in this manual can be included into php file with PHP's include() function:

    <HTML>
    <HEAD>
    <TITLE>My PHP Page.php</TITLE>
    
    <?php include("Netcloak.inc"); ?>
    </HEAD>
    <BODY>
    ...
    </BODY>
    </HTML>
    

    Downloads

    Click to get NetCloak.inc.

    If you prefer, you can get the files split into the NetCloak Sections.


    Conventions

    The remaining pages of this manual give PHP equivalents for NetCloak functions. For each NetCloak function, a PHP example is provided and the extra code required for the example to work follows.

    <NETCLOAK_COMMAND>

    Example:
    <?php echo "The echo construct prints this string that follows." ?>
    
    

    RequiredFunction()

    <?php //---------------- // Information //---------------- function definition; ?>