Functions in PHP are similar to other programming languages. A function is a piece of code that takes one or more input in a sample of parameters, and performs some processing and returns a value. In the previous chapter we were familiar with functions like fopen() and fread() ... They are built-in functions, but PHP also gives you the option to create your own function.
When a file is opened using the fopen() function, it can be read with a fread() function in PHP. This function requires 2 parameters. They must be file pointers and the length of the file in bytes. The length of the file can be determined using the filesize() function in PHP, which takes the filename as an argument and returns the size of the file in bytes. Follow these steps to read a file with PHP: Open the file using the fopen() function . Get the file length using the filesize() function. Read the contents of the file using the fread() function. Close the file using the fclose() function.
There are two ways for the client to send information to Web Server: GET method POST method Before the browser sends the information, it encodes it using a schema called URL encoding. In this schema, the name / value pairs associated with the equal sign and the different pairs are separated by slashes & .
Strings in PHP There is no limit to the length of the string, which can be arbitrarily long if the memory allows. Strings delimited by double quotes are handled by PHP in two ways: Character strings beginning with (\) are replaced with a special character Variables (starting with $) are replaced with a string representation of their value.
Loops in PHP are used to execute the same block of code a specified number of times. PHP supports the following 4 types of loops: For Loop - Loops through a block of code a specified number of times. While Loop - Loops through a block of code if and for as long as a condition has been specified true. Do ... while loop - Loops through a block of code once, and then repeats that loop as long as a given condition becomes true. Foreach loop - Loops through a block of code for each element in an array.
A constant is a name or an identifier for a single value. The value of the constant cannot be changed during script execution. By default, a constant is case sensitive. By convention, constant identifiers are always uppercase. Constant names begin with a letter or an underscore (_), followed by any number of letters, numbers, or underscores. If you have defined a constant, it can never be changed or redefined.
In order to develop and run PHP pages, the following 3 basic components need to be installed on your computer system. Web Server - PHP will work with almost all Web Server software, including Microsoft's Internet Information Server (IIS), but then Apache Server is more commonly used. Download Apache for free from: http://httpd.apache.org/download.cgi
The PHP configuration file, php.ini, is the last and most direct step that affects PHP's functionality. This php.ini file is read every time PHP is initialized, in other words, whenever httpd is restarted for the Module Version or with each Script execution for CGI version. If your changes don't show up, remember to stop and restart httpd. If still not showing, use phpinfo() to check the path to php.ini.