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.
<embed src="flash_game.swf" width="450" height="350" />
#id:first-line { font-weight: bold; color: blue; }
var url = window.location; alert(url);
$homepage = file_get_contents("http://coursesweb.net/"); echo $homepage;