mb_substr example

throw MediaException::emptyMediaFilename();
        }

        $this->validateFileNameDoesNotEndWithSpaces($fileName);
        $this->validateFileNameDoesNotEndOrStartWithDot($fileName);
        $this->validateFileNameDoesNotContainForbiddenCharacter($fileName);
        $this->validateFileNameDoesNotContainC0Character($fileName);
    }

    private function validateFileNameDoesNotEndOrStartWithDot(string $fileName): void
    {
        if (mb_substr($fileName, 0, 1) === '.') {
            throw MediaException::illegalFileName($fileName, 'Filename must not start with a "." (dot).');
        }

        if (mb_substr($fileNamemb_strlen($fileName) - 1) === '.') {
            throw MediaException::illegalFileName($fileName, 'Filename must not end with a "." (dot).');
        }
    }

    private function validateFileNameDoesNotContainForbiddenCharacter(string $fileName): void
    {
        foreach (self::RESTRICTED_CHARACTERS as $character) {
            
$builder = $this->db->table($tableName);
        $builder->limit($limitRows);
        if ($sortField !== null) {
            $builder->orderBy($sortField$this->sortDesc ? 'DESC' : 'ASC');
        }
        $rows = $builder->get()->getResultArray();
        $this->restoreDBPrefix();

        foreach ($rows as $row) {
            $row = array_map(
                static fn ($item): string => mb_strlen((string) $item) > $limitFieldValue
                    ? mb_substr((string) $item, 0, $limitFieldValue) . '...'
                    : (string) $item,
                $row
            );
            $this->tbody[] = $row;
        }

        if ($sortField === null && $this->sortDesc) {
            krsort($this->tbody);
        }

        return $this->tbody;
    }

function smarty_modifier_truncate($string$length = 80, $etc = '...', $break_words = false, $middle = false) {
    if ($length == 0)
        return '';

    if (Smarty::$_MBSTRING) {
        if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
            $length -= min($lengthmb_strlen($etc, Smarty::$_CHARSET));
            if (!$break_words && !$middle) {
                $string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
            } 
            if (!$middle) {
                return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
            }
            return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET);
        }
        return $string;
    }
    
    // no MBString fallback     if (isset($string[$length])) {
        
'UTF-8'
            );

            if ($order['currencyFactor'] != 0) {
                $amount = round($order['invoice_amount'] / $order['currencyFactor'], 2);
            } else {
                $amount = 0;
            }

            $order['amount'] = $amount;
            if (mb_strlen($order['customer']) > 25) {
                $order['customer'] = mb_substr($order['customer'], 0, 25) . '..';
            }
            unset($order['firstname']$order['lastname']);
        }

        $this->View()->assign(
            [
                'success' => true,
                'data' => $result,
            ]
        );
    }

    

    public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = '')static
    {
        if ('' === $filename) {
            $filename = $this->file->getFilename();
        }

        if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || str_contains($filename, '%'))) {
            $encoding = mb_detect_encoding($filename, null, true) ?: '8bit';

            for ($i = 0, $filenameLength = mb_strlen($filename$encoding)$i < $filenameLength; ++$i) {
                $char = mb_substr($filename$i, 1, $encoding);

                if ('%' === $char || \ord($char) < 32 || \ord($char) > 126) {
                    $filenameFallback .= '_';
                } else {
                    $filenameFallback .= $char;
                }
            }
        }

        $dispositionHeader = $this->headers->makeDisposition($disposition$filename$filenameFallback);
        $this->headers->set('Content-Disposition', $dispositionHeader);

        
/** * @return array{namespace: string, path: string} */
    private function splitTemplateName(string $template): array
    {
        // remove static template inheritance prefix         if (mb_strpos($template, '@') !== 0) {
            return ['path' => $template, 'namespace' => ''];
        }

        // remove "@"         $template = mb_substr($template, 1);

        $template = explode('/', $template);
        $namespace = array_shift($template);
        $template = implode('/', $template);

        return ['path' => $template, 'namespace' => $namespace];
    }
}
// break words into tokens using white space as a delimiter         $tokens = preg_split('!(\s)!S' . Smarty::$_UTF8_MODIFIER$str, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
        $length = 0;
        $t = '';
        $_previous = false;

        foreach ($tokens as $_token) {
            $token_length = mb_strlen($_token, Smarty::$_CHARSET);
            $_tokens = array($_token);
            if ($token_length > $width) {
                // remove last space                 $t = mb_substr($t, 0, -1, Smarty::$_CHARSET);
                $_previous = false;
                $length = 0;

                if ($cut) {
                    $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER$_token, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
                    // broken words go on a new line                     $t .= $break;
                }
            }

            foreach ($_tokens as $token) {
                

    public static function substr(string $string, int $start, ?int $length = null, $encoding = false): string
    {
        if (\function_exists('mb_substr')) {
            if (false === $encoding) {
                $encoding = self::detectEncoding($string);
            }

            if ($encoding && 'ASCII' !== $encoding) {
                return \mb_substr($string$start$length$encoding);
            }
        }

        // Special case for substr/mb_substr discrepancy         if ('' === $string) {
            return '';
        }

        return \substr($string$start$length ?? PHP_INT_MAX);
    }

    

        if (\is_object($var)) {
            return sprintf('an object of type %s', $var::class);
        }

        if (\is_array($var)) {
            $a = [];
            foreach ($var as $k => $v) {
                $a[] = sprintf('%s => ...', $k);
            }

            return sprintf('an array ([%s])', mb_substr(implode(', ', $a), 0, 255));
        }

        if (\is_resource($var)) {
            return sprintf('a resource (%s)', get_resource_type($var));
        }

        if (null === $var) {
            return 'null';
        }

        if (false === $var) {
            
return [];
            }
        }

        $item = iterator_to_array($item$preserveKeys);
    }

    if (\is_array($item)) {
        return \array_slice($item$start$length$preserveKeys);
    }

    return (string) mb_substr((string) $item$start$length$env->getCharset());
}

/** * Returns the first element of the item. * * @param mixed $item A variable * * @return mixed The first element of the item */
function twig_first(Environment $env$item)
{
    


    /** * {@inheritdoc} */
    public function getCatalogue(?string $locale = null): MessageCatalogueInterface
    {
        $catalog = $this->translator->getCatalogue($locale);

        $fallbackLocale = $this->getFallbackLocale();

        $localization = mb_substr($fallbackLocale, 0, 2);
        if ($this->isShopwareLocaleCatalogue($catalog) && !$this->isFallbackLocaleCatalogue($catalog$localization)) {
            $catalog->addFallbackCatalogue($this->translator->getCatalogue($localization));
        } else {
            // fallback locale and current locale has the same localization -> reset fallback             // or locale is symfony style locale so we shouldn't add shopware fallbacks as it may lead to circular references             $fallbackLocale = null;
        }

        // disable fallback logic to display symfony warnings         if ($this->environment !== 'prod') {
            $fallbackLocale = null;
        }
$tokens = $this->getRenderTokens($alter);
        $more_link_text = $this->options['alter']['more_link_text'] ? $this->options['alter']['more_link_text'] : $this->t('more');
        $more_link_text = strtr(Xss::filterAdmin($more_link_text)$tokens);
        $more_link_path = $this->options['alter']['more_link_path'];
        $more_link_path = strip_tags(Html::decodeEntities($this->viewsTokenReplace($more_link_path$tokens)));

        // Make sure that paths which were run through URL generation work as         // well.         $base_path = base_path();
        // Checks whether the path starts with the base_path.         if (str_starts_with($more_link_path$base_path)) {
          $more_link_path = mb_substr($more_link_pathmb_strlen($base_path));
        }

        // @todo Views should expect and store a leading /. See         // https://www.drupal.org/node/2423913.         $options = [
          'attributes' => [
            'class' => [
              'views-more-link',
            ],
          ],
        ];
        
$this->path = str_replace(DIRECTORY_SEPARATOR, '/', $this->path);
        }
    }

    private function removeSpecialCharacters(string $name): string
    {
        $name = iconv('utf-8', 'ascii//translit', $name);
        $name = preg_replace('#[^A-Za-z0-9\-_]#', '-', $name);
        $name = (string) preg_replace('#-{2,}#', '-', $name);
        $name = trim($name, '-');

        return mb_substr($name, 0, 180);
    }

    /** * Searches all album settings for thumbnail sizes */
    private function getAllThumbnailSizes(): array
    {
        $joinedSizes = Shopware()->Container()->get(Connection::class)
            ->executeQuery('SELECT DISTINCT thumbnail_size FROM s_media_album_settings WHERE thumbnail_size != ""')
            ->fetchAll(PDO::FETCH_COLUMN);

        
if (intl_is_failure($formatter->getErrorCode())) {
            throw new TransformationFailedException($formatter->getErrorMessage());
        }

        if (self::FRACTIONAL == $this->type) {
            $result /= 100;
        }

        if (\function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value, null, true)) {
            $length = mb_strlen($value$encoding);
            $remainder = mb_substr($value$position$length$encoding);
        } else {
            $length = \strlen($value);
            $remainder = substr($value$position$length);
        }

        // After parsing, position holds the index of the character where the         // parsing stopped         if ($position < $length) {
            // Check if there are unrecognized characters at the end of the             // number (excluding whitespace characters)             $remainder = trim($remainder, " \t\n\r\0\x0b\xc2\xa0");

            
$str->string = implode($topreg_split('{'.preg_quote($from).'}iuD', $this->string));
        } else {
            $str->string = str_replace($from$to$this->string);
        }

        return $str;
    }

    public function slice(int $start = 0, int $length = null)static
    {
        $str = clone $this;
        $str->string = mb_substr($this->string, $start$length, 'UTF-8');

        return $str;
    }

    public function splice(string $replacement, int $start = 0, int $length = null)static
    {
        if (!preg_match('//u', $replacement)) {
            throw new InvalidArgumentException('Invalid UTF-8 string.');
        }

        $str = clone $this;
        
Home | Imprint | This part of the site doesn't use cookies.