Home - martindubenet/PHP GitHub Wiki
Welcome to my shared personnal notes. Navigate the sidebar menu to find all my precious documents. Search for keywords.
<?php
phpinfo();
description | simple string | concatenated strings contained in HTML markup |
---|---|---|
Official | <?php echo $string ?> |
<?php echo '<p>'. $paragraph1 .'</p><p>'. $paragraph2 .'</p>' ?> |
Shorthand | <?= $string ?> |
<?= '<p>'. $paragraph1 .'</p><p>'. $paragraph2 .'</p>' ?> |
For including common blocks of DOM in multiple pages
method | description | function |
---|---|---|
<?php include( '_example.php' ); ?> <?php include_once( '_example.php' ); ?>
|
Any file | include, include_once |
<?php require( '_example.php' ); ?> <?php require_once( '_example.php' ); ?>
|
Mandatory file | require, require_once |
To include relative paths is usually rely on my
$rootPath = '';
variable that I declare in a globe file at the root of a project. This file is then included in the first line of all the php files. At the second line I (re)declare the variable, allowing me to specified the repository levels where that file is located. Example$rootPath = '../../';
. Then I can use it in the DOM as<?php include_once( '{$basePath}inc/_example.php' ); ?>
. Or I can rely on the PHP dirname function to position relatively to the parent repository of that file like<?php include_once( dirname(__FILE__) . '/inc/_example.php' ); ?>
.
NOTE: Look for the “dot+equal”
.=
in the code below.
// original seperated strings as variables
$first_part = "The quick brown fox";
$last_part = " jumped over the lazy dog.";
// basic rendering of the variables (without concatenating them)
$first_part . $last_part
// concatenating the 2 variables into one string
$concatenated_parts = $first_part;
$concatenated_parts .= $last_part;
$string = $concatenated_parts;
The above concatenated $string
= « The quick brown fox jumped over the lazy dog. »
Note that this level of styling is relevant for backend stuff, NOT frontend where the styling is CSS
{text-transform:uppercase;}
.
- Lowercase:
echo strtolower($string)
= « the quick brown fox jumped over the lazy dog. » - Lowercase:
echo strtoupper($string)
= « THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. » - Uppercase
first: echo ucfirst($string)
= « The quick brown fox jumped over the lazy dog. » - Uppercase
words: echo ucwords($string)
= « The Quick Brown Fox Jumped Over The Lazy Dog. »
$var1 = true;
$var2 = false;
$var3 = null;
$var4 = '';
Note that $var2
$var3
and $var4
are all 3 negative results has they are NOT TRUE but $var4
differs since it is empty.
-
echo is_null($var3);
= 1 -
echo is_null($var4);
= 0 -
echo empty($var4);
= 1 -
echo isset($var4);
= 0
$jugg_var1 = '2'; // string
$jugg_var2 = 22; // integer (int)
$jugg_var3 = 3.14; // float
$jugg_var4 = array(3,9,27); // array
$jugg_var5 = true; // boolean (bool)
Just remember that CONSTANT requires uppercase and are fixed values that you can NOT redefine like a variable can.