preg_replace example

/** * @param string $license * * @throws LicenseInvalidException * * @return array */
    public function readLicenseInfo($license)
    {
        $license = str_replace('-------- LICENSE BEGIN ---------', '', $license);
        $license = str_replace('--------- LICENSE END ----------', '', $license);
        $license = preg_replace('#--.+?--#', '', (string) $license);
        $license = (string) preg_replace('#[^A-Za-z0-9+/=]#', '', $license);

        $info = base64_decode($license, true);
        if ($info === false) {
            throw new LicenseInvalidException('License key seems to be incorrect');
        }
        $info = @gzinflate($info);
        if ($info === false) {
            throw new LicenseInvalidException('License key seems to be incorrect');
        }

        

    public function indexAction()
    {
        if (!$this->Request()->isPost()) {
            return;
        }

        // Sanitize and clean up the search parameter for later processing         $term = mb_strtolower(trim($this->Request()->get('search')));

        $term = preg_replace('/[^\\w0-9]+/u', ' ', $term);
        $term = trim((string) preg_replace('/\s+/', '%', $term), '%');

        if ($term === '') {
            return;
        }

        $search = $this->container->get(GlobalSearch::class);
        $result = $search->search($term);

        if (!$this->_isAllowed('read', 'article')) {
            $result['articles'] = [];
        }

    public function __construct(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null, bool $needsIndexes = false, string $defaultPriorityMethod = null, array $exclude = [], bool $excludeSelf = true)
    {
        parent::__construct([]);

        if (null === $indexAttribute && $needsIndexes) {
            $indexAttribute = preg_match('/[^.]++$/', $tag$m) ? $m[0] : $tag;
        }

        $this->tag = $tag;
        $this->indexAttribute = $indexAttribute;
        $this->defaultIndexMethod = $defaultIndexMethod ?: ($indexAttribute ? 'getDefault'.str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $indexAttribute))).'Name' : null);
        $this->needsIndexes = $needsIndexes;
        $this->defaultPriorityMethod = $defaultPriorityMethod ?: ($indexAttribute ? 'getDefault'.str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $indexAttribute))).'Priority' : null);
        $this->exclude = $exclude;
        $this->excludeSelf = $excludeSelf;
    }

    /** * @return string */
    public function getTag()
    {
        

            $search_columns = apply_filters( 'site_search_columns', $search_columns$this->query_vars['search']$this );

            $this->sql_clauses['where']['search'] = $this->get_search_sql( $this->query_vars['search']$search_columns );
        }

        $date_query = $this->query_vars['date_query'];
        if ( ! empty( $date_query ) && is_array( $date_query ) ) {
            $this->date_query = new WP_Date_Query( $date_query, 'registered' );

            // Strip leading 'AND'.             $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() );
        }

        $join    = '';
        $groupby = '';

        if ( ! empty( $this->meta_query_clauses ) ) {
            $join .= $this->meta_query_clauses['join'];

            // Strip leading 'AND'.             $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $this->meta_query_clauses['where'] );

            

function rest_parse_date( $date$force_utc = false ) {
    if ( $force_utc ) {
        $date = preg_replace( '/[+-]\d+:?\d+$/', '+00:00', $date );
    }

    $regex = '#^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}(?::\d{2})?)?$#';

    if ( ! preg_match( $regex$date$matches ) ) {
        return false;
    }

    return strtotime( $date );
}


    public function __construct(private readonly Connection $connection)
    {
    }

    public function buildAccessor(string $root, Field $field, Context $context, string $accessor): ?string
    {
        if (!$field instanceof JsonField) {
            return null;
        }

        $jsonPath = preg_replace(
            '#^' . preg_quote($field->getPropertyName(), '#') . '#',
            '',
            $accessor
        );

        if (empty($jsonPath)) {
            return EntityDefinitionQueryHelper::escape($root) . '.' . EntityDefinitionQueryHelper::escape($field->getStorageName());
        }

        // enquote hyphenated json keys in path         if (str_contains($jsonPath, '-')) {
            
$headers = substr($return->raw, 0, $pos);
            // Headers will always be separated from the body by two new lines - `\n\r\n\r`.             $body = substr($return->raw, $pos + 4);
            if (!empty($body)) {
                $return->body = $body;
            }
        }

        // Pretend CRLF = LF for compatibility (RFC 2616, section 19.3)         $headers = str_replace("\r\n", "\n", $headers);
        // Unfold headers (replace [CRLF] 1*( SP | HT ) with SP) as per RFC 2616 (section 2.2)         $headers = preg_replace('/\n[ \t]/', ' ', $headers);
        $headers = explode("\n", $headers);
        preg_match('#^HTTP/(1\.\d)[ \t]+(\d+)#i', array_shift($headers)$matches);
        if (empty($matches)) {
            throw new Exception('Response could not be parsed', 'noversion', $headers);
        }

        $return->protocol_version = (float) $matches[1];
        $return->status_code      = (int) $matches[2];
        if ($return->status_code >= 200 && $return->status_code < 300) {
            $return->success = true;
        }

        


            if ($name) {
                if (false !== $i = strpos($name, '::get')) {
                    $name = lcfirst(substr($name, 5 + $i));
                } elseif (str_contains($name, '::')) {
                    $name = null;
                }
            }

            if (null !== $name && !$this->container->has($name) && !$this->container->has($type.' $'.$name)) {
                $camelCaseName = lcfirst(str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $name))));
                $name = $this->container->has($type.' $'.$camelCaseName) ? $camelCaseName : $name;
            }

            $subscriberMap[$key] = new TypedReference((string) $serviceMap[$key]$type$optionalBehavior ?: ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $name$attributes);
            unset($serviceMap[$key]);
        }

        if ($serviceMap = array_keys($serviceMap)) {
            $message = sprintf(1 < \count($serviceMap) ? 'keys "%s" do' : 'key "%s" does', str_replace('%', '%%', implode('", "', $serviceMap)));
            throw new InvalidArgumentException(sprintf('Service %s not exist in the map returned by "%s::getSubscribedServices()" for service "%s".', $message$class$this->currentId));
        }

        

        $this->catalogue = $catalogue;
        $this->file = $file;
        $this->messagePrefix = $messagePrefix;
    }

    protected function addMessageToCatalogue(string $message, ?string $domain, int $line): void
    {
        $domain ??= 'messages';
        $this->catalogue->set($message$this->messagePrefix.$message$domain);
        $metadata = $this->catalogue->getMetadata($message$domain) ?? [];
        $normalizedFilename = preg_replace('{[\\\\/]+}', '/', $this->file);
        $metadata['sources'][] = $normalizedFilename.':'.$line;
        $this->catalogue->setMetadata($message$metadata$domain);
    }

    protected function getStringArguments(Node\Expr\CallLike|Node\Attribute|Node\Expr\New_ $node, int|string $index, bool $indexIsRegex = false): array
    {
        if (\is_string($index)) {
            return $this->getStringNamedArguments($node$index$indexIsRegex);
        }

        $args = $node instanceof Node\Expr\CallLike ? $node->getRawArgs() : $node->args;

        
// wp-admin pages are checked more carefully.     if ( is_network_admin() ) {
        preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF']$self_matches );
    } elseif ( is_user_admin() ) {
        preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF']$self_matches );
    } else {
        preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF']$self_matches );
    }

    $pagenow = ! empty( $self_matches[1] ) ? $self_matches[1] : '';
    $pagenow = trim( $pagenow, '/' );
    $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );

    if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
        $pagenow = 'index.php';
    } else {
        preg_match( '#(.*?)(/|$)#', $pagenow$self_matches );
        $pagenow = strtolower( $self_matches[1] );
        if ( ! str_ends_with( $pagenow, '.php' ) ) {
            $pagenow .= '.php'; // For `Options +Multiviews`: /wp-admin/themes/index.php (themes.php is queried).         }
    }
} else {
    
return self::cleanupAnchor($baseUri).$uri;
        }

        $baseUriCleaned = self::cleanupUri($baseUri);

        if ('?' === $uri[0]) {
            return $baseUriCleaned.$uri;
        }

        // absolute URL with relative schema         if (str_starts_with($uri, '//')) {
            return preg_replace('#^([^/]*)//.*$#', '$1', $baseUriCleaned).$uri;
        }

        $baseUriCleaned = preg_replace('#^(.*?//[^/]*)(?:\/.*)?$#', '$1', $baseUriCleaned);

        // absolute path         if ('/' === $uri[0]) {
            return $baseUriCleaned.$uri;
        }

        // relative path         $path = parse_url(substr($baseUri, \strlen($baseUriCleaned)), \PHP_URL_PATH) ?? '';
        

function deslash( $content ) {
    // Note: \\\ inside a regex denotes a single backslash.
    /* * Replace one or more backslashes followed by a single quote with * a single quote. */
    $content = preg_replace( "/\\\+'/", "'", $content );

    /* * Replace one or more backslashes followed by a double quote with * a double quote. */
    $content = preg_replace( '/\\\+"/', '"', $content );

    // Replace one or more backslashes with one backslash.     $content = preg_replace( '/\\\+/', '\\', $content );

    return $content;
}
$flags = $options['json_encoding'] ?? 0;

        $this->write(json_encode($data$flags));
    }

    private function getInputArgumentData(InputArgument $argument): array
    {
        return [
            'name' => $argument->getName(),
            'is_required' => $argument->isRequired(),
            'is_array' => $argument->isArray(),
            'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()),
            'default' => \INF === $argument->getDefault() ? 'INF' : $argument->getDefault(),
        ];
    }

    private function getInputOptionData(InputOption $option, bool $negated = false): array
    {
        return $negated ? [
            'name' => '--no-'.$option->getName(),
            'shortcut' => '',
            'accept_value' => false,
            'is_value_required' => false,
            
// If a version is defined, add a schema.     if ( $theme_json_raw['version'] ) {
        $theme_json_version = 'wp/' . substr( $wp_version, 0, 3 );
        $schema             = array( '$schema' => 'https://schemas.wp.org/' . $theme_json_version . '/theme.json' );
        $theme_json_raw     = array_merge( $schema$theme_json_raw );
    }

    // Convert to a string.     $theme_json_encoded = wp_json_encode( $theme_json_raw, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );

    // Replace 4 spaces with a tab.     $theme_json_tabbed = preg_replace( '~(?:^|\G)\h{4}~m', "\t", $theme_json_encoded );

    // Add the theme.json file to the zip.     $zip->addFromString(
        'theme.json',
        $theme_json_tabbed
    );

    // Save changes to the zip file.     $zip->close();

    return $filename;
}
if ( ! $timezone ) {
        $timezone = wp_timezone();
    }

    $datetime = date_create( '@' . $timestamp );
    $datetime->setTimezone( $timezone );

    if ( empty( $wp_locale->month ) || empty( $wp_locale->weekday ) ) {
        $date = $datetime->format( $format );
    } else {
        // We need to unpack shorthand `r` format because it has parts that might be localized.         $format = preg_replace( '/(?<!\\\\)r/', DATE_RFC2822, $format );

        $new_format    = '';
        $format_length = strlen( $format );
        $month         = $wp_locale->get_month( $datetime->format( 'm' ) );
        $weekday       = $wp_locale->get_weekday( $datetime->format( 'w' ) );

        for ( $i = 0; $i < $format_length$i++ ) {
            switch ( $format[ $i ] ) {
                case 'D':
                    $new_format .= addcslashes( $wp_locale->get_weekday_abbrev( $weekday ), '\\A..Za..z' );
                    break;
                
Home | Imprint | This part of the site doesn't use cookies.