PHP common utility class

Here's a small excerpt from a class that I've developed recently.

class Common 
  {
      
      
      public function createRandomString($length = 8) 
      {
          
          
          $string = '';
          $possible = '0123456789bcdfghjkmnpqrstvwxyz';
          $i = 0;
          
          while($i < $length) {
              
              $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
              
              if (!strstr($password, $char)) { 
                  $string .= $char;
                  $i++;
              }
              
          }
          
          return $string;
          
          
          
      }
      
      public function filterEmail($email) 
      
      {
      
          $filtered = str_replace('@', '@', $email);
          $filtered = str_replace('.', '.', $filtered);
          
          return $filtered;    
          
          
          
      }
      
      
      public function mySQLDateToItalianFormat($date) 
      {
          
          // MwSQL 'date' : yyyy-mm-dd
          
          $day;
          $month;
          $year;
          $formatted_date;
          
          $date_parts = explode('-', $date);
          
          switch($date_parts[2]) {
              
              case '01':
                $day = '1';
                break;
              case '02':
                $day = '2';
                break;
              case '03':
                $day = '3';
                break;
              case '04':
                $day = '4';
                break;
              case '05':
                $day = '5';
                break;
              case '06':
                $day = '6';
                break;
              case '07':
                $day = '7';
                break;
              case '08':
                $day = '8';
                break;
              case '09':
                $day = '9';
                break;
              default:
                $day = $date_parts[2];
                break;
                
              
          }
          
          switch($date_parts[1]) {
              
              case '01':
                $month = 'gennaio';
                break;
              case '02':
                $month = 'febbraio';
                break;
              case '03':
                $month = 'marzo';
                break;
              case '04':
                $month = 'aprile';
                break;
              case '05':
                $month = 'maggio';
                break;
              case '06':
                $month = 'giugno';
                break;
              case '07':
                $month = 'luglio';
                break;
              case '08':
                $month = 'agosto';
                break;
              case '09':
                $month = 'settembre';
                break;
              case '10':
                $month = 'ottobre';
                break;
              case '11':
                $month = 'novembre';
                break;
              case '12':
                $month = 'dicembre';
                break;
              default:
                break;
              
          }
          
          $year = $date_parts[0];
          
          $formatted_date = $day . ' ' . $month . ' ' . $year;
          
          return $formatted_date;
          
          
      }
      
      
      public function mySQLDateTimeToItalianFormat($datetime) {
          
          // datetime format : yyyy-mm-dd hh:mm:ss
          
          $formatted_datetime;
          $date_parts = explode(' ', $datetime);
          
          $date = $date_parts[0];
          $formatted_date = $this->mySQLDateToItalianFormat($date);
          
          $time = $date_parts[1];
          
          $formatted_datetime = $formatted_date . ' ' . $time;
          
          return $formatted_datetime;
          
          
          
      }
      
      
      public function markupURLs($text) {
          
          $url_re = '#\b((https?|ftp|file)://|(www|ftp)\.)[-A-Z0-9+&@\#/%?=~_|$!:,.;]*[a-z0-9+&@\#/%=~_|$]#i';
          
          if(preg_match($url_re, $text)) {
              
              $text = preg_replace($url_re, '<a href="$0">$0</a>', $text);
              
              
          }
          
          return $text;
          
      }
      
      
      
      
  }

Leave a Reply

Note: Only a member of this blog may post a comment.