preg_split example

$parts = explode(';', $type);
        if (!\in_array($parts[0]$this->contentTypes)) {
            return $response;
        }

        // we don't use a proper XML parser here as we can have ESI tags in a plain text response         $content = $response->getContent();
        $content = preg_replace('#<esi\:remove>.*?</esi\:remove>#s', '', $content);
        $content = preg_replace('#<esi\:comment[^>]+>#s', '', $content);

        $boundary = self::generateBodyEvalBoundary();
        $chunks = preg_split('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#', $content, -1, \PREG_SPLIT_DELIM_CAPTURE);

        $i = 1;
        while (isset($chunks[$i])) {
            $options = [];
            preg_match_all('/(src|onerror|alt)="([^"]*?)"/', $chunks[$i]$matches, \PREG_SET_ORDER);
            foreach ($matches as $set) {
                $options[$set[1]] = $set[2];
            }

            if (!isset($options['src'])) {
                throw new \RuntimeException('Unable to process an ESI tag without a "src" attribute.');
            }

    public function trigger_config_file_error($args = null)
    {
        $this->lex = Smarty_Internal_Configfilelexer::instance();
        $this->parser = Smarty_Internal_Configfileparser::instance();
        // get template source line which has error         $line = $this->lex->line;
        if (isset($args)) {
            // $line--;         }
        $match = preg_split("/\n/", $this->lex->data);
        $error_text = "Syntax error in config file '{$this->config->source->filepath}' on line {$line} '{$match[$line-1]}' ";
        if (isset($args)) {
            // individual error message             $error_text .= $args;
        } else {
            // exspected token from parser             foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
                $exp_token = $this->parser->yyTokenName[$token];
                if (isset($this->lex->smarty_token_names[$exp_token])) {
                    // token type from lexer                     $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
                }
 else {
            $res = false;
        }
        return $res;
    }

    private static $escapes_single = Array('\\' => '\\',
                                          '\'' => '\'');
    private static function parse_single_quoted_string($qstr) {
        $escaped_string = substr($qstr, 1, strlen($qstr)-2); //remove outer quotes
        $ss = preg_split('/(\\\\.)/', $escaped_string, -1, PREG_SPLIT_DELIM_CAPTURE);

        $str = "";
        foreach ($ss as $s) {
            if (strlen($s) === 2 && $s[0] === '\\') {
                if (isset(self::$escapes_single[$s[1]])) {
                    $s = self::$escapes_single[$s[1]];
                }
             }

             $str .= $s;
        }

        

    public function getnumchmodfromh( $mode ) {
        $realmode = '';
        $legal    = array( '', 'w', 'r', 'x', '-' );
        $attarray = preg_split( '//', $mode );

        for ( $i = 0, $c = count( $attarray )$i < $c$i++ ) {
            $key = array_search( $attarray[ $i ]$legal, true );

            if ( $key ) {
                $realmode .= $legal[ $key ];
            }
        }

        $mode  = str_pad( $realmode, 10, '-', STR_PAD_LEFT );
        $trans = array(
            
$match[2] = substr($match[2], 1, -1);
        $phrase = TRUE;
        $this->simple = FALSE;
      }

      // Simplify keyword according to indexing rules and external       // preprocessors. Use same process as during search indexing, so it       // will match search index.       $words = $text_processor->analyze($match[2]);
      // Re-explode in case simplification added more words, except when       // matching a phrase.       $words = $phrase ? [$words] : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
      // Negative matches.       if ($match[1] == '-') {
        $this->keys['negative'] = array_merge($this->keys['negative']$words);
      }
      // OR operator: instead of a single keyword, we store an array of all       // ORed keywords.       elseif ($match[2] == 'OR' && count($this->keys['positive'])) {
        $last = array_pop($this->keys['positive']);
        // Starting a new OR?         if (!is_array($last)) {
          $last = [$last];
        }

  protected function getRoutesByPath($path) {
    // Split the path up on the slashes, ignoring multiple slashes in a row     // or leading or trailing slashes. Convert to lower case here so we can     // have a case-insensitive match from the incoming path to the lower case     // pattern outlines from \Drupal\Core\Routing\RouteCompiler::compile().     // @see \Drupal\Core\Routing\CompiledRoute::__construct()     $parts = preg_split('@/+@', mb_strtolower($path), -1, PREG_SPLIT_NO_EMPTY);

    $collection = new RouteCollection();

    $ancestors = $this->getCandidateOutlines($parts);
    if (empty($ancestors)) {
      return $collection;
    }

    // The >= check on number_parts allows us to match routes with optional     // trailing wildcard parts as long as the pattern matches, since we     // dump the route pattern without those optional parts.
/** * @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand */
    public function __construct(string|array $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, string|\Closure $urlFormat = null)
    {
        $fileLinkFormat ??= $_ENV['SYMFONY_IDE'] ?? $_SERVER['SYMFONY_IDE'] ?? '';

        if (!\is_array($f = $fileLinkFormat)) {
            $f = (ErrorRendererInterface::IDE_LINK_FORMATS[$f] ?? $f) ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: 'file://%f#L%l';
            $i = strpos($f, '&', max(strrpos($f, '%f')strrpos($f, '%l'))) ?: \strlen($f);
            $fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f$i), -1, \PREG_SPLIT_DELIM_CAPTURE);
        }

        $this->fileLinkFormat = $fileLinkFormat;
        $this->requestStack = $requestStack;
        $this->baseDir = $baseDir;
        $this->urlFormat = $urlFormat;
    }

    /** * @return string|false */
    
return $line;
        }

        /** * @param Translation_Entry $entry * @param string $po_comment_line */
        public function add_comment_to_entry( &$entry$po_comment_line ) {
            $first_two = substr( $po_comment_line, 0, 2 );
            $comment   = trim( substr( $po_comment_line, 2 ) );
            if ( '#:' === $first_two ) {
                $entry->references = array_merge( $entry->references, preg_split( '/\s+/', $comment ) );
            } elseif ( '#.' === $first_two ) {
                $entry->extracted_comments = trim( $entry->extracted_comments . "\n" . $comment );
            } elseif ( '#,' === $first_two ) {
                $entry->flags = array_merge( $entry->flags, preg_split( '/,\s*/', $comment ) );
            } else {
                $entry->translator_comments = trim( $entry->translator_comments . "\n" . $comment );
            }
        }

        /** * @param string $s * @return string */
 elseif (str_ends_with($signature, '): never') || str_ends_with($signature, '): void')) {
                $body = <<<EOPHP if (isset(\$this->lazyObjectState)) { (\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args}); } else { {$parentCall}; } EOPHP;
            } else {
                if (!$methodsHaveToBeProxied && !$method->isAbstract()) {
                    // Skip proxying methods that might return $this                     foreach (preg_split('/[()|&]++/', self::exportType($method) ?? 'static') as $type) {
                        if (\in_array($type = ltrim($type, '?')['static', 'object'], true)) {
                            continue 2;
                        }
                        foreach ([$class, ...$interfaces] as $r) {
                            if ($r && is_a($r->name, $type, true)) {
                                continue 3;
                            }
                        }
                    }
                }

                
$string = mb_strtolower(html_entity_decode($string), 'UTF-8');

        // Remove not required chars from string         $replaced = preg_replace("/[^\pL_0-9]/u", ' ', $string);
        if (!\is_string($replaced)) {
            return [];
        }
        $string = trim($replaced);

        // Parse string into array         $wordsTmp = preg_split('/ /', $string, -1, PREG_SPLIT_NO_EMPTY);
        if (!\is_array($wordsTmp)) {
            return [];
        }

        if (\count($wordsTmp)) {
            $words = array_unique($wordsTmp);
        } elseif (!empty($string)) {
            $words = [$string];
        } else {
            return [];
        }

        

    
    /** * Increases columns and lines count according to the given string * * @param string $buffer String to analyze * * @return void */
    protected function adjustColumnAndLine($buffer)
    {
        $lines = preg_split($this->linesSplitter, $buffer);
        $linesCount = count($lines) - 1;
        $this->line += $linesCount;
        $columns = mb_strlen($lines[$linesCount], "UTF-8");
        if ($linesCount) {
            $this->column = $columns;
        } else {
            $this->column += $columns;
        }
    }
    
    /** * Consumes characters until one of the given characters is found * * @param array|LSM $stops Characters to search * @param bool $handleEscape True to handle escaping * @param bool $collectStop True to include the stop character * * @return array|null */
// No colored string found. Invalid strings with no `\033[0;??`.             if ($coloredStrings === []) {
                return $newText . self::getColoredText($text$foreground$background$format);
            }

            $nonColoredText = preg_replace(
                $pattern,
                '<<__colored_string__>>',
                $text
            );
            $nonColoredChunks = preg_split(
                '/<<__colored_string__>>/u',
                $nonColoredText
            );

            foreach ($nonColoredChunks as $i => $chunk) {
                if ($chunk !== '') {
                    $newText .= self::getColoredText($chunk$foreground$background$format);
                }

                if (isset($coloredStrings[$i])) {
                    $newText .= $coloredStrings[$i];
                }
// Start with 1 element instead of 0 since the first thing we do is pop.     $chars = array( '' );

    do {
        // We had some string left over from the last round, but we counted it in that last round.         array_pop( $chars );

        /* * Split by UTF-8 character, limit to 1000 characters (last array element will contain * the rest of the string). */
        $pieces = preg_split( $regex$str, 1000, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );

        $chars = array_merge( $chars$pieces );

        // If there's anything left over, repeat the loop.     } while ( count( $pieces ) > 1 && $str = array_pop( $pieces ) );

    return implode( '', array_slice( $chars$start$length ) );
}

if ( ! function_exists( 'mb_strlen' ) ) :
    /** * Compat function to mimic mb_strlen(). * * @ignore * @since 4.2.0 * * @see _mb_strlen() * * @param string $string The string to retrieve the character length from. * @param string|null $encoding Optional. Character encoding to use. Default null. * @return int String length of `$string`. */

    public static function run(array $indexes, array $array): array
    {
        $result = [];

        foreach ($indexes as $index) {
            // See https://regex101.com/r/44Ipql/1             $segments = preg_split(
                '/(?<!\\\\)\./',
                rtrim($index, '* '),
                0,
                PREG_SPLIT_NO_EMPTY
            );

            $segments = array_map(
                static fn ($key) => str_replace('\.', '.', $key),
                $segments
            );

            

    public function getVary(): array
    {
        if (!$vary = $this->headers->all('Vary')) {
            return [];
        }

        $ret = [];
        foreach ($vary as $item) {
            $ret[] = preg_split('/[\s,]+/', $item);
        }

        return array_merge([], ...$ret);
    }

    /** * Sets the Vary header. * * @param bool $replace Whether to replace the actual value or not (true by default) * * @return $this * * @final */
Home | Imprint | This part of the site doesn't use cookies.