PHP year options


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getYearOptions( $selected, $offset, $count )
  2. {
  3. $options = '';
  4.  
  5. $start_year = date( 'Y' ) + $offset;
  6.  
  7. $finish_year = $start_year + $count;
  8.  
  9. for( $x = $start_year; $x <= $finish_year; $x++ )
  10. {
  11. if( strlen( $x ) == 1 ) $x = '0' . $x;
  12.  
  13. $options .= '<option value="' . $x . '"';
  14.  
  15. if( $x == $selected )
  16. {
  17. $options .= ' selected="selected"';
  18. }
  19.  
  20. $options .= '>' . $x . '</option>';
  21. }
  22.  
  23. return $options;
  24. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.