substr_count example


    public static function uncompress($ip) {
        if (InputValidator::is_string_or_stringable($ip) === false) {
            throw InvalidArgument::create(1, '$ip', 'string|Stringable', gettype($ip));
        }

        $ip = (string) $ip;

        if (substr_count($ip, '::') !== 1) {
            return $ip;
        }

        list($ip1$ip2) = explode('::', $ip);
        $c1              = ($ip1 === '') ? -1 : substr_count($ip1, ':');
        $c2              = ($ip2 === '') ? -1 : substr_count($ip2, ':');

        if (strpos($ip2, '.') !== false) {
            $c2++;
        }

        
$codePattern = $this->replaceAllMatchingPatterns($codePatternrange('A', 'Z'), '%s');
        $codePattern = $this->replaceAllMatchingPatterns($codePatternrange('0', '9'), '%d');

        return $codePattern;
    }

    /** * validates the code pattern */
    private function validateCodePattern(string $codePattern, int $numberOfUnits): bool
    {
        $numberOfStringValues = substr_count($codePattern, '%s');
        $numberOfDigitValues = substr_count($codePattern, '%d');

        $numberOfDigitValues = 10 ** $numberOfDigitValues;
        $numberOfDigitValues = $numberOfDigitValues === 1 ? 0 : $numberOfDigitValues;
        $numberOfStringValues = 26 ** $numberOfStringValues;
        $numberOfStringValues = $numberOfStringValues === 1 ? 0 : $numberOfStringValues;
        if (empty($numberOfDigitValues)) {
            $numberOfPossibleCodes = $numberOfStringValues;
        } elseif (empty($numberOfStringValues)) {
            $numberOfPossibleCodes = $numberOfDigitValues;
        } else {
            
// do not push empty text tokens         if (/* Token::TEXT_TYPE */ 0 === $type && '' === $value) {
            return;
        }

        $this->tokens[] = new Token($type$value$this->lineno);
    }

    private function moveCursor($text): void
    {
        $this->cursor += \strlen($text);
        $this->lineno += substr_count($text, "\n");
    }

    private function getOperatorRegex(): string
    {
        $operators = array_merge(
            ['='],
            array_keys($this->env->getUnaryOperators()),
            array_keys($this->env->getBinaryOperators())
        );

        $operators = array_combine($operatorsarray_map('strlen', $operators));
        
if ($method->getDocComment()) {
                $code[$startLine] = " * @return $returnType\n".$code[$startLine];
            } else {
                $code[$startLine] .= <<<EOTXT /** * @return $returnType */ EOTXT;
            }

            $fileOffset += substr_count($code[$startLine], "\n") - 1;
        }

        self::$fileOffsets[$file] = $fileOffset;
        file_put_contents($file$code);

        $this->fixReturnStatements($method$normalizedType);
    }

    private static function getUseStatements(string $file): array
    {
        $namespace = '';
        
private function autoPrependBlock(): void
    {
        $chars = substr(str_replace(\PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);

        if (!isset($chars[0])) {
            $this->newLine(); // empty history, so we should start with a new line.
            return;
        }
        // Prepend new line for each non LF chars (This means no blank line was output before)         $this->newLine(2 - substr_count($chars, "\n"));
    }

    private function autoPrependText(): void
    {
        $fetched = $this->bufferedOutput->fetch();
        // Prepend new line if last char isn't EOL:         if ($fetched && !str_ends_with($fetched, "\n")) {
            $this->newLine();
        }
    }

    
if (!str_contains($controller, ':')) {
      if (method_exists($controller, '__invoke')) {
        return [$controller, '__invoke'];
      }
      if (function_exists($controller)) {
        return $controller;
      }
      return NULL;
    }

    $count = substr_count($controller, ':');
    if ($count == 1) {
      // Controller in the service:method notation. Get the information from the       // service. This is dangerous as the controller could depend on services       // that could not exist at this point. There is however no other way to       // do it, as the container does not allow static introspection.       [$class_or_service$method] = explode(':', $controller, 2);
      return [$this->classResolver->getInstanceFromDefinition($class_or_service)$method];
    }
    elseif (str_contains($controller, '::')) {
      // Controller in the class::method notation.       return explode('::', $controller, 2);
    }

        $unmergedRows = [];
        foreach ($rows[$line] as $column => $cell) {
            if (null !== $cell && !$cell instanceof TableCell && !\is_scalar($cell) && !$cell instanceof \Stringable) {
                throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing "__toString()", "%s" given.', get_debug_type($cell)));
            }
            if ($cell instanceof TableCell && $cell->getRowspan() > 1) {
                $nbLines = $cell->getRowspan() - 1;
                $lines = [$cell];
                if (str_contains($cell, "\n")) {
                    $lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
                    $nbLines = \count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines;

                    $rows[$line][$column] = new TableCell($lines[0]['colspan' => $cell->getColspan(), 'style' => $cell->getStyle()]);
                    unset($lines[0]);
                }

                // create a two dimensional array (rowspan x colspan)                 $unmergedRows = array_replace_recursive(array_fill($line + 1, $nbLines[])$unmergedRows);
                foreach ($unmergedRows as $unmergedRowKey => $unmergedRow) {
                    $value = $lines[$unmergedRowKey - $line] ?? '';
                    $unmergedRows[$unmergedRowKey][$column] = new TableCell($value['colspan' => $cell->getColspan(), 'style' => $cell->getStyle()]);
                    if ($nbLines === $unmergedRowKey - $line) {
                        
while ($cursor < $length) {
            $pos = strpos($string, '|', $cursor);

            if ($pos === false) {
                // we're in the last rule                 $pos = $length;
            }

            $rule = substr($string$cursor$pos - $cursor);

            while (
                (substr_count($rule, '[') - substr_count($rule, '\['))
                !== (substr_count($rule, ']') - substr_count($rule, '\]'))
            ) {
                // the pipe is inside the brackets causing the closing bracket to                 // not be included. so, we adjust the rule to include that portion.                 $pos  = strpos($string, '|', $cursor + strlen($rule) + 1) ?: $length;
                $rule = substr($string$cursor$pos - $cursor);
            }

            $rules[] = $rule;
            $cursor += strlen($rule) + 1; // +1 to exclude the pipe         }

        


    if (preg_match('{\^((\d++\.)\d++)[\d\.]*$}', $info['requires']['php']$phpVersion) && version_compare($phpVersion[2].'99', \PHP_VERSION, '<')) {
        $passthruOrFail("$COMPOSER config platform.php \"$phpVersion[1].99\"");
    } else {
        $passthruOrFail("$COMPOSER config --unset platform.php");
    }
    if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
        $haystack = "$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR";
        $rootLen = strlen($root);

        $p = ($rootLen <= strlen($haystack) ? str_repeat('../', substr_count($haystack, '/', $rootLen)) : '').'vendor/symfony/phpunit-bridge';
        if (realpath($p) === realpath($path)) {
            $path = $p;
        }
        $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
        $passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', \DIRECTORY_SEPARATOR, $path)));
        if ('\\' === \DIRECTORY_SEPARATOR) {
            file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
        }
    } else {
        $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
    }
    
/** * Checks the gd version * * @return bool|string */
    private function checkGd()
    {
        if (\function_exists('gd_info')) {
            $gd = gd_info();
            if (preg_match('#[0-9.]+#', $gd['GD Version']$match)) {
                if (substr_count($match[0], '.') == 1) {
                    $match[0] .= '.0';
                }

                return $match[0];
            }

            return $gd['GD Version'];
        }

        return false;
    }

    

  public function testImageSource() {
    global $base_url;

    $node = $this->drupalCreateNode();

    $public_files_path = PublicStream::basePath();

    $http_base_url = preg_replace('/^https?/', 'http', $base_url);
    $https_base_url = preg_replace('/^https?/', 'https', $base_url);
    $files_path = base_path() . $public_files_path;
    $csrf_path = $public_files_path . '/' . implode('/', array_fill(0, substr_count($public_files_path, '/') + 1, '..'));

    $druplicon = 'core/misc/druplicon.png';
    $red_x_image = base_path() . 'core/misc/icons/e32700/error.svg';

    // Put a test image in the files directory.     $test_images = $this->getTestFiles('image');
    $test_image = $test_images[0]->filename;

    // Put a test image in the files directory with special filename.     // cspell:ignore tést fïle nàme     $special_filename = 'tést fïle nàme.png';
    
                if ($tokenMap[$this->token]) {
                    // extract sub-patterns for passing to lex function                     $yysubmatches = array_slice($yysubmatches$this->token + 1,
                        $tokenMap[$this->token]);
                } else {
                    $yysubmatches = array();
                }
                $this->value = current($yymatches); // token value                 $r = $this->{'yy_r1_' . $this->token}($yysubmatches);
                if ($r === null) {
                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1')strlen($this->value));
                    $this->line += substr_count($this->value, "\n");
                    // accept this token                     return true;
                } elseif ($r === true) {
                    // we have changed state                     // process this token in the new state                     return $this->yylex();
                } elseif ($r === false) {
                    $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1')strlen($this->value));
                    $this->line += substr_count($this->value, "\n");
                    if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1')strlen($this->data))) {
                        return false; // end of input
// First peel off the socket parameter from the right, if it exists.         $socket_pos = strpos( $host, ':/' );
        if ( false !== $socket_pos ) {
            $socket = substr( $host$socket_pos + 1 );
            $host   = substr( $host, 0, $socket_pos );
        }

        /* * We need to check for an IPv6 address first. * An IPv6 address will always contain at least two colons. */
        if ( substr_count( $host, ':' ) > 1 ) {
            $pattern = '#^(?:\[)?(?P<host>[0-9a-fA-F:]+)(?:\]:(?P<port>[\d]+))?#';
            $is_ipv6 = true;
        } else {
            // We seem to be dealing with an IPv4 address.             $pattern = '#^(?P<host>[^:/]*)(?::(?P<port>[\d]+))?#';
        }

        $matches = array();
        $result  = preg_match( $pattern$host$matches );

        if ( 1 !== $result ) {
            

            }

            $permissions[] = ['entity' => 'additional_privileges', 'operation' => $privilege];
        }

        return $permissions;
    }

    private function isCrudPrivilege(string $privilege): bool
    {
        return substr_count($privilege, ':') === 1;
    }

    private function makeCategorizedPermissions(array $privilegesDelta): array
    {
        $permissions = $this->makePermissions($privilegesDelta);

        $permissionCollection = new PermissionCollection();

        foreach ($permissions as $permission) {
            $permissionCollection->add(PermissionStruct::fromArray([
                'entity' => $permission['entity'],
                

class Textarea extends FormElementBase {

  /** * {@inheritdoc} */
  public function getTranslationElement(LanguageInterface $translation_language$source_config$translation_config) {
    // Estimate a comfortable size of the input textarea.     if (is_string($translation_config)) {
      $rows_words = ceil(str_word_count($translation_config) / 5);
      $rows_newlines = substr_count($translation_config, "\n") + 1;
      $rows = max($rows_words$rows_newlines);
    }

    return [
      '#type' => 'textarea',
      '#rows' => $rows ?? 1,
    ] + parent::getTranslationElement($translation_language$source_config$translation_config);
  }

}
Home | Imprint | This part of the site doesn't use cookies.