PHP function to reset instance variables

Posted by & filed under Programming.

Quick snippet to reset all public instance variables inside a PHP class back to their original values. Can’t take credit for the code though. Found it on a website somewhere and have used it in pretty much every class I build. Problem is I can’t remember where it was originally.

How to close all projects in NetBeans

Posted by & filed under Programming.

File this under “duh.” I typically have several projects open in NetBeans and occasionally go through and close them all to clean up a little.  Turns out if you shift click on the projects you want closed there’s a new item on the File menu “Close X Projects.”  Easy…

Just finished up a couple of WordPress plugins

Posted by & filed under Programming.

Needed a break from a larger web app I’m working on and this weekend kicked out a couple of WordPress plugins that I’ve had on my idea file for a while now. The first is called rTwit and lets you embed any Twitter feed you want into a post or page. Most of the Twitter… Read more »

JavaScript version of PHP __FILE__ or __DIR__

Posted by & filed under Programming.

This is one of those issues I keep coming back to.  I need a way to get the path of the current JavaScript file.  Something analogous to the PHP __DIR__ constant or dirname(__FILE__). Found something close on Stack Overflow.  The solution there gets the entire file.  A bit of substring and lastIndexOf and I had… Read more »

Trimming all members of an array in PHP

Posted by & filed under Programming.

Needed a quick way to go through and trim leading and trailing spaces off of a string array in PHP. I’ve used array_walk to do it before, but with the addition of anonymous functions it makes it a little quicker without having to do a separate function. Love those one line and done techniques.

htaccess to deny access, except for includes

Posted by & filed under Programming.

It’s usually a bad idea to allow php include files to be directly accessed. My general method is to either declare a constant in the index.php and check for that constant in the included file or make sure that the included file doesn’t match $_SERVER[‘REQUEST_URI’]. Sure, either of those work. But I came across a… Read more »

Dynamically link to CSS with JavaScript

Posted by & filed under Internet, Programming.

Needed a way to add a CSS file with JavaScript, so I went out a-Googling like I normally do.  Problem is everything I found either worked in Internet Explorer and not in FireFox or the other way around.  Nothing I found worked in both.  So I hacked together a function of my own.  Should have… Read more »

phpMailer – Could not instantiate mail function

Posted by & filed under Programming.

Had a client getting this error when trying to send emails last week and have now spent several hours on Google trying to find a solution. Biggest catch is that other scripts were able to send mail, so it seemed unlikely that it was the host. So I took the phpMailer class and uploaded it… Read more »

bit.ly and PHP

Posted by & filed under Programming.

Needed a quick and easy way to create a bit.ly URL for another site of mine. Google came through for me. David Walsh posted a short PHP function on his site that takes your bit.ly login, API key, and the URL to shorten and returns a nice, short bit.ly link. Link: http://davidwalsh.name/bitly-php Just put the… Read more »

Quick PHP wrapper for print_r

Posted by & filed under Programming.

Working on web apps I find myself using the print_r command a lot, and I mean a lot. It helps trace out what data is going where, and more often what’s not going where it’s supposed to. A few months ago I realized that I type this same bit of code way too often. Does… Read more »