JBZoo\Utils\Str::sub PHP Method

sub() public static method

Get part of string
public static sub ( string $string, integer $start, integer $length ) : string
$string string
$start integer
$length integer
return string
    public static function sub($string, $start, $length = 0)
    {
        if (self::isMBString()) {
            if (0 == $length) {
                $length = self::len($string);
            }
            return mb_substr($string, $start, $length, self::$encoding);
        } else {
            // @codeCoverageIgnoreStart
            return substr($string, $start, $length);
            // @codeCoverageIgnoreEnd
        }
    }

Usage Example

 public function migrate()
 {
     try {
         $this->isOk();
         if (isset($this->params['auto'])) {
             print "Auto mode selected." . PHP_EOL;
             $params = new OdaPrepareReqSql();
             $params->sql = "SELECT `param_value`\n                    FROM `" . self::$config->BD_ENGINE->prefixTable . "api_tab_parametres`\n                    WHERE 1=1\n                    AND `param_name` = 'install_date'\n                ";
             $params->typeSQL = OdaLibBd::SQL_GET_ONE;
             $retour = $this->BD_ENGINE->reqODASQL($params);
             if ($retour->data) {
                 $installDate = $retour->data->param_value;
                 $compressInstallDate = Filter::int(Str::sub($installDate, 2, 2) . Str::sub($installDate, 5, 2) . Str::sub($installDate, 8, 2));
                 print "Install date is: " . $installDate . PHP_EOL;
                 $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator('.' . DIRECTORY_SEPARATOR, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($objects as $folderPath => $object) {
                     if ($object->isDir()) {
                         $filePath = $folderPath . DIRECTORY_SEPARATOR . 'do.sql';
                         if (file_exists($filePath)) {
                             $banned_words = "-install -reworkModel -matrixRangApi";
                             if (!preg_match('~\\b(' . str_replace(' ', '|', $banned_words) . ')\\b~', $filePath) && preg_match('/[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])/', $filePath)) {
                                 $patchDate = Filter::int(Str::sub($filePath, 6, 6));
                                 if ($patchDate > $compressInstallDate) {
                                     $this->exe($filePath);
                                 }
                             }
                         }
                     }
                 }
             } else {
                 print "No install_date retrieve." . PHP_EOL;
             }
         } else {
             print "Target mode selected." . PHP_EOL;
             if ($this->params['partial'] !== "all") {
                 $this->exe('.' . DIRECTORY_SEPARATOR . $this->params['target'] . DIRECTORY_SEPARATOR . $this->params['partial'] . DIRECTORY_SEPARATOR . $this->params['option'] . '.sql');
             } else {
                 $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator('.' . DIRECTORY_SEPARATOR . $this->params['target'], \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($objects as $name => $object) {
                     if ($object->isDir()) {
                         $this->exe($name . DIRECTORY_SEPARATOR . $this->params['option'] . '.sql');
                     }
                 }
             }
         }
         echo 'Success' . PHP_EOL;
         return $this;
     } catch (Exception $ex) {
         die($ex . '');
     }
 }
All Usage Examples Of JBZoo\Utils\Str::sub