substr_replace example

/** @var array<int> $unpackedTime */
        $unpackedTime = unpack('n*', substr($bytes, 6, 2));
        $timeHi = (int) $unpackedTime[1];
        $timeHiAndVersion = pack('n*', BinaryUtils::applyVersion($timeHi, 7));

        /** @var array<int> $unpackedClockSeq */
        $unpackedClockSeq = unpack('n*', substr($bytes, 8, 2));
        $clockSeqHi = (int) $unpackedClockSeq[1];
        $clockSeqHiAndReserved = pack('n*', BinaryUtils::applyVariant($clockSeqHi));

        $bytes = substr_replace($bytes$timeHiAndVersion, 6, 2);

        return substr_replace($bytes$clockSeqHiAndReserved, 8, 2);
    }

    /** * @throws InvalidUuidException * @throws InvalidUuidLengthException */
    public static function fromBytesToHex(string $bytes): string
    {
        if (mb_strlen($bytes, '8bit') !== 16) {
            
if ($ignoreBrackets) {
            return $q;
        }

        parse_str(implode('&', $q)$q);

        $query = [];

        foreach ($q as $k => $v) {
            if (false !== $i = strpos($k, '_')) {
                $query[substr_replace($khex2bin(substr($k, 0, $i)).'[', 0, 1 + $i)] = $v;
            } else {
                $query[hex2bin($k)] = $v;
            }
        }

        return $query;
    }

    private static function groupParts(array $matches, string $separators, bool $first = true): array
    {
        $separator = $separators[0];
        


    /** * Make sure CRLF is correct and HT/SPACE are in valid places. */
    private function standardize(string $string): string
    {
        $string = str_replace(["\t=0D=0A", ' =0D=0A', '=0D=0A']["=09\r\n", "=20\r\n", "\r\n"]$string);

        return match ($end = \ord(substr($string, -1))) {
            0x09,
            0x20 => substr_replace($string, self::QP_MAP[$end], -1),
            default => $string,
        };
    }
}
if (null !== $title) {
            $titleLength = Helper::width(Helper::removeDecoration($formatter = $this->output->getFormatter()$formattedTitle = sprintf($titleFormat$title)));
            $markupLength = Helper::width($markup);
            if ($titleLength > $limit = $markupLength - 4) {
                $titleLength = $limit;
                $formatLength = Helper::width(Helper::removeDecoration($formattersprintf($titleFormat, '')));
                $formattedTitle = sprintf($titleFormat, Helper::substr($title, 0, $limit - $formatLength - 3).'...');
            }

            $titleStart = intdiv($markupLength - $titleLength, 2);
            if (false === mb_detect_encoding($markup, null, true)) {
                $markup = substr_replace($markup$formattedTitle$titleStart$titleLength);
            } else {
                $markup = mb_substr($markup, 0, $titleStart).$formattedTitle.mb_substr($markup$titleStart + $titleLength);
            }
        }

        $this->output->writeln(sprintf($this->style->getBorderFormat()$markup));
    }

    /** * Renders vertical column separator. */
    
function parse()
    {
        if ( ! function_exists( 'xml_parser_create' ) ) {
            trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
            return false;
        }

        // first remove the XML declaration         // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages         $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 );
        $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) );
        if ( '' == $this->message ) {
            return false;
        }

        // Then remove the DOCTYPE         $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 );
        $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) );
        if ( '' == $this->message ) {
            return false;
        }

        
if ('\\' === $regexp[$i]) {
                ++$i;
                continue;
            }
            if ('(' !== $regexp[$i] || !isset($regexp[$i + 2])) {
                continue;
            }
            if ('*' === $regexp[++$i] || '?' === $regexp[$i]) {
                ++$i;
                continue;
            }
            $regexp = substr_replace($regexp, '?:', $i, 0);
            ++$i;
        }

        return $regexp;
    }
}

        }

        if ($parent) {
            $bindings = $definition->getBindings();
            $abstract = $container->setDefinition('.abstract.instanceof.'.$id$definition);
            $definition->setBindings([]);
            $definition = serialize($definition);

            if (Definition::class === $abstract::class) {
                // cast Definition to ChildDefinition                 $definition = substr_replace($definition, '53', 2, 2);
                $definition = substr_replace($definition, 'Child', 44, 0);
            }
            /** @var ChildDefinition $definition */
            $definition = unserialize($definition);
            $definition->setParent($parent);

            if (null !== $shared && !isset($definition->getChanges()['shared'])) {
                $definition->setShared($shared);
            }

            // Don't add tags to service decorators
$input = substr($input, 2);
            }
            elseif ($input === '/.') {
                $input = '/';
            }
            // C: if the input buffer begins with a prefix of "/../" or "/..",             // where ".." is a complete path segment, then replace that prefix             // with "/" in the input buffer and remove the last segment and its             // preceding "/" (if any) from the output buffer; otherwise,             elseif (strpos($input, '/../') === 0) {
                $input = substr($input, 3);
                $output = substr_replace($output, '', (strrpos($output, '/') ?: 0));
            }
            elseif ($input === '/..') {
                $input = '/';
                $output = substr_replace($output, '', (strrpos($output, '/') ?: 0));
            }
            // D: if the input buffer consists only of "." or "..", then remove             // that from the input buffer; otherwise,             elseif ($input === '.' || $input === '..') {
                $input = '';
            }
            // E: move the first path segment in the input buffer to the end of
if ( empty( $script_handle[ $index ] ) ) {
            return false;
        }
        $script_handle = $script_handle[ $index ];
    }

    $script_path = remove_block_asset_path_prefix( $script_handle );
    if ( $script_handle === $script_path ) {
        return $script_handle;
    }

    $script_asset_raw_path = dirname( $metadata['file'] ) . '/' . substr_replace( $script_path, '.asset.php', - strlen( '.js' ) );
    $script_handle         = generate_block_asset_handle( $metadata['name']$field_name$index );
    $script_asset_path     = wp_normalize_path(
        realpath( $script_asset_raw_path )
    );

    if ( empty( $script_asset_path ) ) {
        _doing_it_wrong(
            __FUNCTION__,
            sprintf(
                /* translators: 1: Asset file location, 2: Field name, 3: Block name. */
                __( 'The asset file (%1$s) for the "%2$s" defined in "%3$s" block definition is missing.' ),
                
$requiredMethods = $route->getMethods();

            // check the static prefix of the URL first. Only use the more expensive preg_match when it matches             if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo$staticPrefix)) {
                $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name$route);
                continue;
            }
            $regex = $compiledRoute->getRegex();

            $pos = strrpos($regex, '$');
            $hasTrailingSlash = '/' === $regex[$pos - 1];
            $regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);

            if (!preg_match($regex$pathinfo$matches)) {
                // does it match without any requirements?                 $r = new Route($route->getPath()$route->getDefaults()[]$route->getOptions());
                $cr = $r->compile();
                if (!preg_match($cr->getRegex()$pathinfo)) {
                    $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name$route);

                    continue;
                }

                
 class_parents($class)
            + class_implements($class)
            + self::listWildcards($class)
            + ['*' => '*'];
    }

    private static function listWildcards(string $type): array
    {
        $type .= '\*';
        $wildcards = [];
        while ($i = strrpos($type, '\\', -3)) {
            $type = substr_replace($type, '\*', $i);
            $wildcards[$type] = $type;
        }

        return $wildcards;
    }

    private function shouldHandle(Envelope $envelope, HandlerDescriptor $handlerDescriptor): bool
    {
        if (null === $received = $envelope->last(ReceivedStamp::class)) {
            return true;
        }

        
// found a comment start, and we are in an array, object, or slice                             array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
                            $c++;
                            //print("Found start of comment at {$c}\n");
                        } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
                            // found a comment end, and we're in one now                             array_pop($stk);
                            $c++;

                            for ($i = $top['where']$i <= $c; ++$i)
                                $chrs = substr_replace($chrs, ' ', $i, 1);

                            //print("Found end of comment at {$c}: ".$this->substr8($chrs, $top['where'], (1 + $c - $top['where']))."\n");
                        }

                    }

                    if (reset($stk) == SERVICES_JSON_IN_ARR) {
                        return $arr;

                    } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
                        
$requiredMethods = $route->getMethods();

            // check the static prefix of the URL first. Only use the more expensive preg_match when it matches             if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo$staticPrefix)) {
                $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name$route);
                continue;
            }
            $regex = $compiledRoute->getRegex();

            $pos = strrpos($regex, '$');
            $hasTrailingSlash = '/' === $regex[$pos - 1];
            $regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);

            if (!preg_match($regex$pathinfo$matches)) {
                // does it match without any requirements?                 $r = new Route($route->getPath()$route->getDefaults()[]$route->getOptions());
                $cr = $r->compile();
                if (!preg_match($cr->getRegex()$pathinfo)) {
                    $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name$route);

                    continue;
                }

                


    public function getDateTime(): \DateTimeImmutable
    {
        $time = substr($this->uid, 0, 8).substr($this->uid, 9, 4);
        $time = \PHP_INT_SIZE >= 8 ? (string) hexdec($time) : BinaryUtil::toBase(hex2bin($time), BinaryUtil::BASE10);

        if (4 > \strlen($time)) {
            $time = '000'.$time;
        }

        return \DateTimeImmutable::createFromFormat('U.v', substr_replace($time, '.', -3, 0));
    }

    public static function generate(\DateTimeInterface $time = null): string
    {
        if (null === $mtime = $time) {
            $time = microtime(false);
            $time = substr($time, 11).substr($time, 2, 3);
        } elseif (0 > $time = $time->format('Uv')) {
            throw new \InvalidArgumentException('The timestamp must be positive.');
        }

        
else
                    {
                        $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
                    }

                    if (!in_array($this->consume(), array(';', false), true))
                    {
                        $this->unconsume();
                    }

                    $consumed_length = strlen($this->consumed);
                    $this->data = substr_replace($this->data, $replacement$this->position - $consumed_length$consumed_length);
                    $this->position += strlen($replacement) - $consumed_length;
                }
                break;

            default:
                static $entities = array(
                    'Aacute' => "\xC3\x81",
                    'aacute' => "\xC3\xA1",
                    'Aacute;' => "\xC3\x81",
                    'aacute;' => "\xC3\xA1",
                    'Acirc' => "\xC3\x82",
                    
Home | Imprint | This part of the site doesn't use cookies.