One of the functions added in PHP 5 is file_get_contents. This function allows you to just pass a file name and it will return the entire contents of the file. That’s all well and good if you’re using PHP5, but PHP4 is still very common.
One of the functions added in PHP 5 is file_get_contents. This function allows you to just pass a file name and it will return the entire contents of the file. That’s all well and good if you’re using PHP5, but PHP4 is still very common.
During a support issue with a user of one of my web applications I made a fairly important discovery about GoDaddy.com and how they have PHP installed on their servers. Many functions – 44 last time I looked – are disabled. Now, this may just be with their economy package and they have them enabled on their higher packages as an incentive to upgrade, but it caught me off guard.
Here’s a quick PHP function that will return the size of all files in a directory.
To use: pass the directory you want to check as the only variable, eg: directory_size(“/home/web/directory”)
For the past few months I’ve been using TSW Web Coder for web development. It is an outstanding program. Unfortunately, my computer is too slow for it. The biggest problem was random crashes. Re-installs would help, but I got tired of it. So, out I went looking for a replacement. I found PHP Designer 2005.
PHP is an interpreted language; and as such, the computer needs to process the script each time it is run. Honestly, I don’t know much about the internal workings of PHP; so I don’t know how it handles comments in the code. More specifically, I don’t know how well it handles comments.
I have seen sites over the web going back and forth on whether it’s possible to have too many comments. Most I found said that it didn’t really matter; a few said it slowed execution. As I tend to be the type to over comment my code, I decided to test it for myself with some over the top commented code.
Do you ever find yourself needing to shorten a string in PHP? Maybe return the first 25 words of a long story? Give this routine a try. It will return the first n words from a string, or the entire string if it is less than n words long.
It should be pretty easy to get $_GET, $_POST, $_SESSION, or $_COOKIE variables in PHP code. The problem is that just entering $_GET[‘variable’] causes an error if the variable does not exist. What’s needed is a way to open the variable, and get a blank string if the variable is not defined.
Often times in PHP you find yourself needing to insert text. Most sites do this by using a database backend, but you also have the option to include data from a text file. Three methods are available for this; require, include, and file_get_contents. Which is fastest, which is best? When should you use one over the other?
PHP allows you to define a string using either a single quote (‘) or a double quote (“). Why? Is one better? Faster? Why should you use one over the other. In this article, I am going to benchmark both methods; both with literal strings and strings with variables included.
Often a PHP developer will find themselves needing to know how long a function they are writing takes. Maybe a page seems to be taking too long to load, or maybe they have two different functions that perform the same task and need to see which one performs faster. This is where benchmarking comes in.
Can't find what you're looking for? Try refining your search: