Skip navigation.
Home
That which cannot be rendered in binary is by definition a delusion
 

Reply to comment

Less Than Zerofill

I honestly have not completely figured out where, when, or why, but my zerofilled integers are coming back at me as true (non zero padded) integers. This creates problems as in when the dates stored are four ints (0501) are parsed for the first two digits, it is the integer 501 that is parsed, not the string '0501'.

This means of course that my attempt to get the month by substr($row->date, 0, 2) gives me 50, not '05'.

The solution of course is a custom row class within your orm: (this use case taken from Zend_DB)

public function __get($pField)
{
  $value = parent::__get($pField);
 switch(strtolower($pField)):
    case 'startdate': // or any other zerofilled fields
      return CPF_Util_Format::number_pad($value, 5);
     break;
    default:
      return $value;
  endswitch;
 }


// in class CPF_Util_Format

	public static function number_pad($number,$n) {
		return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
	}

If you're not using an orm you can always tactically pad your numbers when you need formatted strings but its much more of a bother.

Reply

  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <p> <span><small> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options