php

  1. Fun with SQL: Part 1

    So about 2 years ago, the guy who built the CRM which I work on at work decided that storing dates in the format mm/dd/yyyy as a tinytext was appropriate for one of the tables. So today, after making a bunch of changes to the file that processes this data to format it correctly, I had to change the db data to match the new format. Thus, the magical str_to_date sql statement comes into play. Here it is for future reference:

    UPDATE table 
    SET timestamp=str_to_date( `timestamp` , '%m/%d/%Y %h:%i:%s' )
    

    This takes the current data (mm/dd/yyyy) and converts it to the proper data type for a DATETIME field (YYYY-MM-DD HH:MM:SS).

  2. URL file access with a cURL backup

    So in the process of getting my website up and running, I ran into the ‘URL file-access is disabled in the server configuration’ message. Since the server admin was asleep, I figured I’d try to find a workaround. cURL is a commonly used one for this scenario, but the problem is that if you switch hosts it may not be available. As such, here’s a handy variable to tell if URL file access is enabled:

    ini_get('allow_url_fopen')

    It returns true or false depending on the value in the php.ini file, and you can throw it in an if statement to test for it, and use cURL in the else statement in case it fails.

  3. Valid Blogger RSS Output

    Having trouble getting your blogger rss output to validate because Google botched the tracking code (lack of alt attribute in the tracking image)?

    Do what I did, add this to the php page processing the rss feed:

    $entry['content'] = substr($entry['content'], 0, -8) . " alt='' />";
    

    This cuts out the closing img and div tag, adds alt, and closes it all again… just pray google doesn’t change it >.>