Payne's PHP Notes

Back to Payne's PHP Notebook.

1. Terms, Syntax, Variables, and String Variables

Terms

Syntax

<?php

    // Single-line comment

    /*
        Block comment
    */

    some code;
?>

Variables

String Variables

$text1 = "PHP";
$text2 = "rocks!";
$text3 = "PHP is cool!";

Name Keyword / Operator Example Result Comment
Concatenation Operator . $text1 . " " . $text2 PHP rocks!  
String Length strlen(string) strlen($text3) 12  
String Position strpos(stringSource, string2) strpos($text3, "cool") 7  
    strpos($text3, "like") FAULSE
Concatenation Assignment $text1 .= $text2; $text1 .= " ";$text1 .= $text2; PHP rocks!  

NameFunctionResult
Replacement$stringResult = str_replace("search", "replace", $stringSource);
// Example
$stringResult = str_replace("cool","awesome",$text3);
echo $stringResult;
PHP is awesome!