Monthly Archives: May 2012
PHP Tutorial: strip_tags Is Brawnier Than I Thought
| May 31, 2012 | Posted by Greg Bulmash under PHP |
First, I want to direct you to Kise's comment on yesterday's post. Nested ternary operators, FTW! In my day job, I do a combination of PHP development, front-end dev, and developing HTML e-mail newsletter templates. For that last part, I have to suck in a bunch of HTML from RSS feeds, pull off all the…
PHP Tutorial: Convoluted Code - Combining Ternary Operators and Anonymous Functions
| May 30, 2012 | Posted by Greg Bulmash under PHP |
Following on yesterday's post about chaining if statements without brackets on a single line, I tried to explore other ways to perform this "test if the variable is set, then do a comparison if it is" logic. I created one of the most convoluted lines of code I've ever written. It's no SQL join that…
PHP Tutorial: Chaining "If" on a Single Line
| May 29, 2012 | Posted by Greg Bulmash under PHP |
When I want to test a variable's existence and its value, I've always done this: if(isset($var)){ if($var == "Betty") echo "Betty's here!"; } The reason for this is because this code will return an error when $var is not set: if((isset($var))&&($var == "Betty")) echo "Betty's Here"; It's always felt a little inefficient. So out of…
Friday Funny: The General Problem
| May 25, 2012 | Posted by Greg Bulmash under PHP |
Today's post (being that we're heading into a holiday weekend in the U.S.) is something funny. I have this on my door at MSNBC. I'll be back with a new post on Tuesday, after the holiday.
PHP Tutorial: Two Functions For Exploring A Class
| May 24, 2012 | Posted by Greg Bulmash under PHP |
So, I ran into these functions while browsing the PHP documentation for something else, and they were cool-yet-puzzling. They are method_exists() and get_class_methods(). On the one hand, they seem really useful to make sure you're calling a method that's there in a class/object, or to list out the methods in the class for inspection. But…
PHP Tutorial: __FILE__ vs. $_SERVER['SCRIPT_FILENAME']
| May 23, 2012 | Posted by Greg Bulmash under PHP |
First thing I want to do is thank everyone who has commented on the site the last few days. The whole point of doing this is trying to level up as a developer, make myself learn, and then reinforce it by writing about it. But the comments are extremely helpful, even the ones that critique…
Building My Own Small PHP Framework: The Singleton Database
| May 22, 2012 | Posted by Greg Bulmash under PHP |
Yesterday, I talked about setting up an autoloader so I wasn't having to have a huge stack of require_once or include statements starting off every HTML stub. To minimize the number of database connections I initialized, I wanted to instantiate the database object just once. Researching how to do that, I was turned on to…
Building My Own Small PHP Framework: Autoloading Classes
| May 21, 2012 | Posted by Greg Bulmash under PHP |
Last week I finished up the demo of how to write captions on photos with PHP and ImageMagick. One of the things I said I was going to do was build a site using that technology at picscribbler.com. While PicScribbler has hosted some of the tech demos, it's not up and running because I'm building…
PHP Tutorial: String Matching - Episode 2 - The Wrath of Khan Academy
| May 18, 2012 | Posted by Greg Bulmash under PHP |
So, in my tutorial on case-insensitive string matching, I suggested using strtolower() as a great equalizer. But the first comment on that showed that instead of having to chop things down to size, there are other ways. strcasecmp($var1, $var2) This lovely function does a case insensitive string comparison for you and will return 0 if…
PHP Tutorial: The Raw Post Contents Part 2
| May 17, 2012 | Posted by Greg Bulmash under PHP |
In Part 1, I showed you that file_get_contents("php://input"); would return the raw post contents. For example, here's a comparison of the file_get_contents input and the $_POST array on a simple form: File: email=douglas%2Bfargo%40globaldynamics.com&username=SuperElf _POST: Array ( [email] => douglas+fargo@globaldynamics.com [username] => SuperElf ) Note that the $_POST array has urldecoded the e-mail address. If it…
Recent Comments