Cutting a string to a specified length is accomplished with the substr() function. For example, the following string variable, which we will cut to a maximum of 30 characters.
Krumo is an open source plugin for your programs that is designed as a replacement to print_r() and var_dump(). These functions are used by developers (myself included) to find out what the program is doing. The main problem is that if there is a lot of data to look at the page can get a bit busy.
It is possible to find out what functions and variables are available from an object at runtime using the PHP functions get_class_methods() and get_object_vars().
Take the following class called testClass.
The $_SERVER superglobal array contains lots of information about the current page location. You can print this off in full using the following line of code.
PHP5 allows you to stop classes being extended or to stop child classes overwriting functions.
The first way to use the final keyword is to stop child classes from overwriting functions when they are created. This can be used to stop an important function from being overwritten. To use the final keyword here just add it to the start of function name.
There is little syntactical difference between MySQL 4 and MySQL 5, but sometimes finding that difference can pinpoint a bug. The mysql_get_server_info() function will tell you what version of MySQL you are using. You can call it with no parameters, in which case it picks the most recently created MySQL resource, or with the resource handle created with mysql_connect().
Here is an example of how to use it.
Sending multiple arguments to a function can be done using a parameter string. This is just like a URL that has data encoded into it. For example, if you wanted to send two parameters (called parameter1 and parameter2) to a function then you would use the following string.
To use this in the function you create the function as normal with a single parameter. This single parameter is the string that will contain all of your arguments.
When navigating the file structure in Unix/Linux environments you will often find yourself typing cd to change the directory and then immediately typing ls to see the contents of the directory.
It is possible to run ls automatically every time you run cd by adding the following commands to your .bashrc file.
You can often forget what you are not running as a super user, so if you type in a command that you can't run with your current set of privileges it will tell give you a permission denied response.
An alternative is to use the !! command to run the last command in the .bash_history. Use this with the sudo command to run the last command as a super user.
If you want to know the length of a string in PHP you would normally turn to the strlen() function which simply tells you the length of the string.