Cleaning PHP code is Fun

Really. I’m serious. At least in this case, it was fun, because I know now that it’s done, my life will be a lot easier.

My work site is powered by PHP. The off-the-shelf script I used to power the home manager is called Free Realty. I’m using an older version of it where the code isn’t as clean (and even the new version isn’t as clean as it probably could be, but it’s fairly plug and play). But the version I have used a TON of echo statements to create its various pages. Now, echo statements are fine if you’re processing variables inside those echoes, but there were just large echo statements full of HTML, and it was just annoying to look at, especially so since HomeSite doesn’t color code the HTML inside PHP tags — meaning it’s really hard to read. So today I got rid of a bunch of echo tags, did a lot more in-line PHP if/else stuff, replaced the longer echo blocks with short-tag versions of echo in-line with the HTML, reduced the amount of overall if/else statements and the code is a lot cleaner and easier on the eyes. It will make a future project I’m working on a hell of a lot easier, too (as I plan on reusing a lot of this same code).

I’m starting to pretend pretty well that I know what I’m doing with this stuff 😉 Prior to this job, I didn’t know a damn thing about PHP, other than knowing a coworker or two were studs at it. But working here was the first real shot I’ve had at it, and it’s a blast. Beats working on the piece of crap ASP server I have upstairs any day of the week.

Comments

Jon says:

Sounds like a good start, but take it a step further: templates, man, templates.

🙂

Step ahead of you 🙂
I used template-like includes for every site I do, including this one.

Jon says:

Excellent……. 🙂

Hervard says:

It’s good when you learn new things like this, and get paid to do it. Sounds like me with a job that I had. I was required to build a database-driven news site, so I taught myself PHP/MySQL and made it. I think I had a whole bunch of echo statements, heh.

since you use homesite, have you gotten any of the extensions for php from my php4hs site?
(www.wilk4.com/asp4hs/php4hs.htm)
Other user wrote ’em, and many are pretty handy. (and free)

Jake says:

Jeff: I had not, and will be downloading them. Thanks!