Categories
PHP Programming

PHP Function Of The Day: ob_end_clean()

Sometimes you get in to a situation where you are working in an environment that drops everything into an output buffer before it spits it out the browser. In most languages this is called “output buffering”. The problem with having EVERYTHING buffered is being able to do special stuff like dynamic XML documents.

My solution to this little pickle was to just drop everything from the current output buffer and then kill the process after I’m done with it. To do this, just execute “ob_end_clean()” right before the functions/objects/code you need to execute. What “ob_end_clean()” does is drops all information that is currently stored in the output buffer, and then stops the buffering anything after it.

One “gotch ya” moment I had using this function was that it doesn’t end ALL cases of output buffering. If for some strange reason there is nested buffering going on, you’ll need to call the function as many times as it takes to get to the top of the call stack.

http://us2.php.net/manual/en/function.ob-end-clean.php

Categories
Other

The Idea That Wasn’t Meant To Be

Two summers ago I had a brilliant idea. College kids hate spending money. Books for classes cost money. Wouldn’t it be great if you knew whether or not you needed the book for class? That way, you could save money!

“Should I Get The Book?” was born out of this thought process. I worked hard on getting the coding part out of the way. It took about 4 weeks to get functional, working every day after work for 3 hours. After the coding was out of the way, I tried to make the site as nice as I could. I was a bit lazy with this though, and essentially “borrowed” a WordPress template and let ‘er rip.

I added schools, added subjects, added classes, and even seeded some reviews. Nobody came. I submitted my site for review to Hacker News, and they basically told me the idea was great, but the site wasn’t usable. In my infinite wisdom, I trudged ahead. I thought, if I advertise enough, people will surely come and leave reviews.

I ended up trying a few different advertising campaigns (Adwords, Facebook), and all brought some traffic, but nobody returned. It turns out that the site was fairly hard to use (which I’d been told by HN) and that without some kind of incentive nobody was going to leave reviews. There was also the part about nobody wanting to leave reviews because there weren’t any reviews there already (chicken & and egg problem?).

After unsuccessfully marketing my product for a few months and trying to get people to seed reviews, I gave up on the original and started on my redesign. The redesign was going to be grand! A huge ajaxy call to action form field in the middle of the screen just begging to be used, a karma system for people who seed reviews, special status for moderators, and incentives to invite your friends. The overall design also allowed people to discern the site’s purpose without reading a single word. Unfortunately, life has a way of putting a damper on even the best laid plans.

I quit grad school in January just as I was starting to make progress on the re-design. When I secured a real job, I found it became much harder to balance work, the fiance, side projects, and free time. I made the choice to sit on Should I Get the Book until the winter when I would have a bit more free time to work on it. Bad choice.

My fiance informed me today that Rate My Professor now has functionality that mimics Should I Get The Book. They implemented it better, already have a user base, and have the money and time to make it happen.

Does this make me sad? Sure it does. But I also feel like a weight has been lifted off my shoulders. For so long I thought Should I Get The Book would be my salvation from the life of a salary man, but as it turns out, it was only holding me back from other ideas that are probably better anyways.

Maybe I didn’t try hard enough. Maybe I didn’t put enough money into it. Or maybe I didn’t sacrifice enough. It could be any of these things, but I tend to think that this idea just wasn’t meant to be.

Categories
PHP Programming

Converting MySQL dateTime to RFC-822 (RSS pubDate) in PHP

I had the need to convert a MySQL datetime time stamp into a format accepted by the RSS 2.0 specification. To get the first part, you can do a SQL query like the following:

1
SELECT DATE_FORMAT(dateTimeColumn, '%a, %d %b %Y %T') AS rssPubDate FROM yourTable

After that, you need to get the timezone, which can be accomplished by using this:

1
$timeZone = date('T');

So lets say you store the rssPubDate from MySQL in a variable called $rssPubDate, all you need to do is $rssPubDate .= ” {$timeZone}”;

That’s it! You now have a RFC-822 compliant time stamp.

Categories
Other

Unobtrusive Subversion

Sometimes you enter a development environment that just isn’t going to work well with version control software.  Maybe they don’t want to use version control software, or maybe the way their infrastructure is set up makes it hard to do.
I currently work at such a place, so I came up with a way to use Subversion for the vast majority of projects that I work on.
Note:  This method works only if you have full ownership over a project.  Any other people working on it would have their changes overwritten.

If I have full ownership over a project, I do the following.
1) Import the project of relevant subdirectory into a new Subversion repository.
2) Make my edits locally, committing whenever I feel inclined.
3) When it’s time to update on the server, I do an “svn export” of the project, and then Rsync it with the server.
It’s not ideal situation, but it works well for now.
Categories
PHP Programming

Supressing Error Messages in PHP

Every once in awhile PHP decides to throw some errors.  Usually it’s because you didn’t do something right, but what if it’s throwing errors anyways?  What if you are on a production server and you need to suppress the errors?

In that case add the following the the top of your file, or include it as a header.

{code type=PHP}
ini_set(“display_errors”, 0);
ini_set(“log_errors”, 1);
{/code}

Optionally, if only a particular statement is throwing an error, you can do this:

{code type=PHP}

$myName = @get_name();

{/code}

The “@” symbol will suppress any errors that the calling function makes.

Remember, suppressing errors is no substitute for good coding.  But, sometimes you do what you have to do.

Categories
PHP Programming

Showing All Errors in PHP

When I was first starting to create web sites with PHP, I struggled with getting error reporting turned on.  Turns out, that you can have it enable at the server, or in the document, or in both.  For development, it’s probably a good idea to have this at the top of script:

error_reporting(E_ALL);
ini_set('display_errors', '1');

This will allow php to display all errors, notices, and warnings.  Simple things like developing with error reporting full on like this help prevent security breaches and unknown application behavior.

Categories
Wordpress Development

Aristo, a jQuery UI Theme

I recently posted a question to Hacker News about using Theme Roller for site design.  The general concensus was that it’s great, but sometimes looks a little childish.  So, a fellow HN user released http://taitems.tumblr.com/post/482577430/introducing-aristo-a-jquery-ui-theme.  It’s called Aristo, and it really cleans up the jQuery UI stuff.

Take a look if you get bored.  It’s worth it.

Categories
PHP Programming Wordpress Development

WP Hacker News Plugin

I’ve been on a WordPress kick lately, and decided that Hacker News needed a WordPress plugin.  This plugin simply places a nice little Y Combinator badge in the upper right-hand corner of your post, with a link that says “Submit to HN”.  If you’d like to check it out, it’s used on this post.

Also, it can be downloaded here.

If you have any questions or need support, please leave a comment.