How to execute an HTTP POST using PHP cURL

I’ve been doing a lot of API integration recently and cURL ends up being exceptionally handy when you are POSTing to an endpoint. Fortunately using cURL in PHP is really easy: // Sets our destination URL $endpoint_url = 'https://somesite.com/path/to/endpoint'; // Creates our data array that we want to post to the endpoint $data_to_post = [ 'field1' => 'foo', 'field2' => 'bar', 'field3' => 'spam',...

Read Full Article →

Looping through a date range

Looping through a date range isn’t as simple as looping through an array with foreach but it doesn’t take much additional code to get the job done. To loop through a date range you will need to use a loop (I prefer a while loop) and increment the date by using strtotime. I’ll convert the timestamp back to a human readable date as well...

Read Full Article →

Difference between break; and continue;

The topic of break and continue came up the other day and I thought it would make for a good blog post. You’re probably familiar with break moreso than continue because it is part of a switch statement’s syntax. Both break and continue can also be used inside of looping statements like while, for and foreach. According to php.net continue can also be used...

Read Full Article →

PHP without fancy braces

PHP is a C-style language and thus uses fancy braces to wrap or hug control structures. PHP is also a language that is extremely flexible so you can also get by without using fancy braces. You will never get away from them entirely as functions and classes / class methods must have fancy braces and currently do not offer an alternative syntax. Let’s take...

Read Full Article →

Debugging SimpleXML Objects

SimpleXML is pretty much the de facto standard for dealing with XML in PHP. The biggest problem with SimpleXML is that it is a pseudo-object that you can’t print_r() or var_dump() to see what’s going on. I recently ran into a situation where it would have been super nice to dump the entire object and see what was going on. Fortunately my Google-fu was...

Read Full Article →