Constants are similar to variables only in the sense that are used to store values, but otherwise, constants and variables differ in many ways.
To create a constant, it is used the define() function instead of the assignment operator (=):
define("CONSTANT_NAME", 'value', [case-insensitive]);-The case-insensitive parameter at the end of the definition is optional (a boolean value: true or false), and by default is false, meaning that the defined constant is in fact case-sensitive.
<?php define("BROTHERS", 'Victor, Alex'); define("COUSIN", "Vasile", true); // defined case-insensitive echo 'My brothers: '. BROTHERS. '<br />'; // My brothers: Victor, Alex // Try to redefine the BROTHERS constant define("BROTHERS", 'Relu'); // Notice: Constant BROTHERS already defined in ... echo 'My cousin: '. COUSIN. '<br />'; // My cousin: Vasile // assign the constant's value (the one case-insensitive) to a variable $cname = Cousin; echo 'My cousin: '. $cname; // My cousin: Vasile ?>
The scope of a defined constant is global, meaning it can be used in any defined function or class that is also part of that code file, including any other included files or functions.
<?php define("BROTHERS", 'Victor, Alex'); echo defined("BROTHERS"); // 1 ?>- The parameter with the name of the constant must be added within double quotes.
<ul> <li>http://coursesweb.net/html/</li> <li>http://coursesweb.net/css/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net