PHP For Beginners - Lesson 4


1. A constant is similar to a variable in that it stores a value that becomes accessible by name (but without the preceding $ character that is used to access variables). However, unlike a variable, once a value is assigned to a constant, it can never be changed.
2. You define constants using the define() function, passing it a name and a value (for example, define('MAX_USERS', 128);).
3. Predefined constants are those that PHP has already defined for you to provide information you can access such as the path and filename of the current file (for example, echo __FILE__;).
4. The print and echo commands are very similar to each other in that they both display values provided to them. The differences are that print accepts only a single argument but has a return value of 1, so it can be used in some places where echo cannot, but echo is a little faster and also supports multiple arguments separated by commas (which print does not).
5. The statement ($var == TRUE) ? echo "true" : echo "false"; is not valid PHP because echo doesn’t return a value and therefore cannot be used within expressions. In such instances, print can be used instead (for example, ($var == TRUE) ? print "true" : print "false";).
6. The superglobal arrays that handle information sent to a PHP program via forms sent using Get and Post methods are $_GET[] and $_POST[].
7. The $_COOKIE[] superglobal array contains cookie data.
8. You can display the URL of a page from which a user was referred to the current one (if available) with a statement such as echo $_SERVER[ 'HTTP_REFERER'];.
9. To sanitize input and other data by replacing any HTML tags with entities that only display the tag names, you can run them through the htmlentities() function (for example, echo htmlentities($_POST['bio']);).
10. You can get PHP to display its configuration information and the current environment and script with the phpinfo() function—for example, phpinfo(32); will display the PHP predefined variables.

PHP For Beginners - Lesson 4

No comments:

Post a Comment