Category: Software Development
-
Chat Personas
Going to make this brief since it’s Easter and I forgot to blog ahead of time this week. So I’ve recently been hanging out on a few Slack teams. One with the work crew, one with my small group of tech friends and a couple of “public” teams with local…
-
Serializing and unserializing variables in PHP
Serialization in PHP is the act of converting a variable into a storable value. When I say storable, I mean being able to store the result in say, a database or a flat file. This is commonly applied to arrays and objects as they are not simply text strings. Under…
-
Decouple your code from your web server
I used to be quite adamant about running nearly the same exact software stack locally as I did on my servers. Running Linux made it easy to pull this off and being able to do the same on OS X was a contingency for switching. I have never been a…
-
Calculate the length of a string with PHP
Calculating the length of a string is a useful feature of any language, in fact it’s one of the few pieces of functionality that has a consistently simple syntax across modern languages. You can calculate the length of a string as part of some server side user input validation or…
-
How to get a server’s hostname in PHP
The hostname of your server or local system is an easy way to determine which environment you are working with, either local or production. Prior to PHP 5.3 you would need to utilize the php_uname() function and with 5.3+ there is a built-in function for getting the hostname: pre-5.3 $hostname…
-
How to save a remote file to disk with PHP
You may already be familiar with file_get_contents() for reading the contents of a local file but did you know that you can use it to read the contents of a remote file or site? You can then use file_put_contents() to write the file’s contents back to disk: file_put_contents(‘./some/local/file’, file_get_contents(‘http://phpave.com’)); Both…
-
Never stop learning
As cliché as this post’s title is, I tend to forget this simple truth from time to time. This week was one of those weeks where I learned a ton of shit. Worked with some new to me libraries. Learned a new term that I’m on the verge of over…
-
Basic HTTP Authentication with PHP
Basic HTTP Authentication is easily accomplished at the web server level (by way of .htaccess with Apache or inside your nginx configuration file) but did you know you could pull it off inside of a PHP script? You bet your butt you can! First, you will need to interrogate the…
-
Life of Pi – Working with Pi in PHP
The irrational mathematical constant of Pi can be obtained a few different ways in PHP. There is a function to give you the value as well as a bunch of constants that represent Pi as well as fractions of Pi and it’s square root. Heck, you could even do it…
-
How to replace a string with a string in PHP
String replacements in PHP are very simple and as per usual, can be done in a variety of different ways. First let’s take a look at the most simple form of a string replacement: str_replace(‘blue’, ‘red’, ‘My favorite color is blue’); The first argument is the string you want to…