Contao\StringUtil::trimsplit PHP Метод

trimsplit() публичный статический Метод

Split a string into fragments, remove whitespace and return fragments as array
public static trimsplit ( string $strPattern, string $strString ) : array
$strPattern string The split pattern
$strString string The input string
Результат array The fragments array
    public static function trimsplit($strPattern, $strString)
    {
        $strKey = md5($strPattern . $strString);
        // Load from cache
        if (isset(static::$arrSplitCache[$strKey])) {
            return static::$arrSplitCache[$strKey];
        }
        // Split
        if (strlen($strPattern) == 1) {
            $arrFragments = array_map('trim', explode($strPattern, $strString));
        } else {
            $arrFragments = array_map('trim', preg_split('/' . $strPattern . '/ui', $strString));
        }
        // Empty array
        if (count($arrFragments) < 2 && !strlen($arrFragments[0])) {
            $arrFragments = array();
        }
        static::$arrSplitCache[$strKey] = $arrFragments;
        return $arrFragments;
    }

Usage Example

Пример #1
0
 /**
  * Display a wildcard in the back end
  *
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         /** @var BackendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['rssReader'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     $this->objFeed = new \SimplePie();
     $arrUrls = \StringUtil::trimsplit('[\\n\\t ]', trim($this->rss_feed));
     if (count($arrUrls) > 1) {
         $this->objFeed->set_feed_url($arrUrls);
     } else {
         $this->objFeed->set_feed_url($arrUrls[0]);
     }
     $this->objFeed->set_output_encoding(\Config::get('characterSet'));
     $this->objFeed->set_cache_location(TL_ROOT . '/system/tmp');
     $this->objFeed->enable_cache(false);
     if ($this->rss_cache > 0) {
         $this->objFeed->enable_cache(true);
         $this->objFeed->set_cache_duration($this->rss_cache);
     }
     if (!$this->objFeed->init()) {
         $this->log('Error importing RSS feed "' . $this->rss_feed . '"', __METHOD__, TL_ERROR);
         return '';
     }
     $this->objFeed->handle_content_type();
     return parent::generate();
 }
All Usage Examples Of Contao\StringUtil::trimsplit