Wednesday, September 9

Literal... Interpreted... Quotes Matter

Something I never before (but probably should have) read that took hours to figure out:

If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters. -via php.net
This really matters!!

For example. When you are sending mail, new lines are usually \r\n. If you have your message body in single quotes (') the \r\n will show up in the message!

Even more importantly. When using Pear mime, you have to define eol. Just remember $crlf = '\r\n' WILL NOT WORK!!! it has to be $crlf = "\r\n" If I had read to the bottom of the user comments on the pear page, it would have saved me a lot of time.

And yes, this post is actually about doing Mail_Mime with Pear :D

Resources:
PEAR Mail_Mime
PHP Maniac Examples

Tuesday, September 8

getdate() Without Time

I am rewriting the front end of a site, but can't change the back end or functionality. And so I must learn how to use an MSSql db via php. My first impression... they are not friends. Okay, moving on.

Problem:
Table has a datetime field, but the backend freaks out because of some 10yr old stored procedure. We traced it down to that the datetime can't contain the time.

Solution:
Now, I could have just used php date, but the day I found out that databases can insert their own date, I swore I'd never use it again for a current timestamp. So instead, my insert statement has this completely inelegent line:

convert(varchar(8), getdate(), 112)
That inserts the date with no time. Or more specifically, the time is 12:00AM. The actual contents is something like Sep 08 2009 12:00AM.

Wednesday, September 2

Buttons Change on Hover

First time I've done this (I think). Short sweet code.

<a href="link"><img src="images/button.jpg"
onmouseover="this.src='images/buttonhover.jpg';"
onmouseout="this.src='images/button.jpg';" /></a>
It would not surprise me if there were instances where this fails. But it's also pretty nice because you don't have to worry about a no js version; it just doesn't do anything without js.

If you're using large images, you might want to preload them.