After 15 years since its arrival, PHP has firmly cemented its place in the online world. Its power and flexibility is so great it is found in over 20 million domains and is part of some the biggest websites around today, like Facebook, YouTube, Wikipedia and more.
As with any programming language it is always useful to know a few tips that will save time and increase efficiency.
Allocating memory – PHP scripts can eat up memory if left unregulated. To counter this, servers usually set a random limit. This can be a problem for certain developers who need more memory to execute their code. This can be easily fixed by editing the php.ini file to include the following code.
memory_limit=16M
The maximum limit however, is controlled by the host.
Including files – If you need to include a .php file within the current file, you can easily do it with the php include function. This can be useful to include a fixed menu, header, footer, etc. The code to use should be of the following format.
<?php include (‘directory/file.php’); ?>
Choice – if statements let you display information based on conditions. This is very easy to use, as demonstrated by the following example:
Assuming that the variable age has been defined
<?php if
(“$telephone1” != “”) {
echo (“$telephone1”);
} ?>
Quote wisely – Proper usage of single and double quotes will save you a lot of time during execution. Keep in mind that double-quotes indicate to the code that there is a variable present. This in turn consumes processor time as the code checks for the presence of any variables. If you simply require something to be printed on screen then you should use only single quotes, as it will require less processor time.