Tag: PHP
-
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…
-
Looping through a date range with PHP
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…
-
Difference between break; and continue; in PHP
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…
-
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…
-
Debugging SimpleXML Objects with PHP
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…
-
Parsing SOAP responses with PHP’s SimpleXML
We recently discussed parsing XML with SimpleXML and since that writing I ran into a situation where I needed to parse a SOAP response. As it turns out, SOAP responses are a totally different beast when it comes to parsing them with SimpleXML. SOAP responses contain namespaces on some if…
-
How to calculate Independence Day observances with PHP
On this 238th anniversary of the United States of America, I felt it appropriate to post an article on how to determine what day the July 4th National Holiday is observed on. There are two rules to the observances. First, if the holiday falls on a Saturday, it is observed…
-
How to parse XML with PHP’s SimpleXML
Parsing XML in PHP couldn’t be easier thanks to the SimpleXML extension. SimpleXML allows you to read in an XML string, verify that it is in fact XML and can create an object that you can interact with by way of the node names in the XML.The SimpleXML extension also…
-
Checking your IMAP email using PHP
I have an upcoming freelance project coming up that includes checking an IMAP email account as well as working with XML in PHP. Let’s talk about connecting to an IMAP account in PHP, don’t worry, I’ll discuss parsing XML next week 😉 For the sake of example, we’re going to…
-
How to calculate Mother’s Day and Father’s Day with PHP
A little late on the Mother’s Day part, but since today is Father’s Day, I figured it would be fun to discuss how to obtain the dates for these moving holidays. To do so, all we need to use is use strtotime and tell it when the holiday will occur…