parse_url example



    function fetch($URI)
    {

        //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);         $URI_PARTS = parse_url($URI);
        if (!empty($URI_PARTS["user"]))
            $this->user = $URI_PARTS["user"];
        if (!empty($URI_PARTS["pass"]))
            $this->pass = $URI_PARTS["pass"];
        if (empty($URI_PARTS["query"]))
            $URI_PARTS["query"] = '';
        if (empty($URI_PARTS["path"]))
            $URI_PARTS["path"] = '';

        switch(strtolower($URI_PARTS["scheme"]))
        {
            
foreach ($attributes as &$attribute) {
            $attribute = trim($attribute, '"\'');
        }
        unset($attribute);

        if (empty($uri)) {
            return $uri;
        }

        if (strpos($uri, 'http') === 0) {
            $uri = parse_url($uri, PHP_URL_PATH);
        }

        $link = new Link($rel$uri);
        foreach ($attributes as $key => $value) {
            $link = $link->withAttribute($key$value);
        }

        $this->linkProvider = $this->linkProvider->withLink($link);

        return $uri;
    }

    
'language',
      'd7_language_negotiation_settings',
      'language_prefixes_and_domains',
    ]);

    global $base_url;
    $config = $this->config('language.negotiation');
    $this->assertSame('language', $config->get('session.parameter'));
    $this->assertSame(LanguageNegotiationUrl::CONFIG_DOMAIN, $config->get('url.source'));
    $this->assertSame('site_default', $config->get('selected_langcode'));
    $expected_domains = [
      'en' => parse_url($base_url, PHP_URL_HOST),
      'fr' => 'fr.drupal.org',
      'is' => 'is.drupal.org',
    ];
    $this->assertSame($expected_domains$config->get('url.domains'));
  }

  /** * Tests the migration with non-existent variables. */
  public function testLanguageNegotiationWithNonExistentVariables() {
    $this->sourceDatabase->delete('variable')
      


        $this->multi->handlesActivity[$this->id] = [new FirstChunk()];

        if ('HEAD' === $context['http']['method'] || \in_array($this->info['http_code'][204, 304], true)) {
            $this->multi->handlesActivity[$this->id][] = null;
            $this->multi->handlesActivity[$this->id][] = null;

            return;
        }

        $host = parse_url($this->info['redirect_url'] ?? $this->url, \PHP_URL_HOST);
        $this->multi->lastTimeout = null;
        $this->multi->openHandles[$this->id] = [&$this->pauseExpiry, $h$this->buffer, $this->onProgress, &$this->remaining, &$this->info, $host];
        $this->multi->hosts[$host] = 1 + ($this->multi->hosts[$host] ?? 0);
    }

    private function close(): void
    {
        $this->canary->cancel();
        $this->handle = $this->buffer = $this->inflate = $this->onProgress = null;
    }

    
use Doctrine\DBAL\Tools\DsnParser;
use Relay\Relay;
use Symfony\Component\Cache\Adapter\AbstractAdapter;

/** * @author Nicolas Grekas <p@tchwork.com> */
class SessionHandlerFactory
{
    public static function createHandler(object|string $connection, array $options = []): AbstractSessionHandler
    {
        if ($query = \is_string($connection) ? parse_url($connection) : false) {
            parse_str($query['query'] ?? '', $query);

            if (($options['ttl'] ?? null) instanceof \Closure) {
                $query['ttl'] = $options['ttl'];
            }
        }
        $options = ($query ?: []) + $options;

        switch (true) {
            case $connection instanceof \Redis:
            case $connection instanceof Relay:
            
self::$handlers[$type] = $class;
    }

    /** * Parse a URL into an array * * @param string $url * @return array */
    public static function parse_URL($url)
    {
        $params = parse_url($url);
        $params['extras'] = array();
        if (isset($params['query']))
        {
            parse_str($params['query']$params['extras']);
        }
        return $params;
    }
}
'REMOTE_ADDR' => '127.0.0.1',
            'SCRIPT_NAME' => '',
            'SCRIPT_FILENAME' => '',
            'SERVER_PROTOCOL' => 'HTTP/1.1',
            'REQUEST_TIME' => time(),
            'REQUEST_TIME_FLOAT' => microtime(true),
        ]$server);

        $server['PATH_INFO'] = '';
        $server['REQUEST_METHOD'] = strtoupper($method);

        $components = parse_url($uri);
        if (false === $components) {
            trigger_deprecation('symfony/http-foundation', '6.3', 'Calling "%s()" with an invalid URI is deprecated.', __METHOD__);
            $components = [];
        }
        if (isset($components['host'])) {
            $server['SERVER_NAME'] = $components['host'];
            $server['HTTP_HOST'] = $components['host'];
        }

        if (isset($components['scheme'])) {
            if ('https' === $components['scheme']) {
                
// Check if the page linked to is on our site.         $pos1 = strpos( $pagelinkedtostr_replace( array( 'http://www.', 'http://', 'https://www.', 'https://' ), '', get_option( 'home' ) ) );
        if ( ! $pos1 ) {
            return $this->pingback_error( 0, __( 'Is there no link to us?' ) );
        }

        /* * Let's find which post is linked to. * FIXME: Does url_to_postid() cover all these cases already? * If so, then let's use it and drop the old code. */
        $urltest = parse_url( $pagelinkedto );
        $post_id = url_to_postid( $pagelinkedto );
        if ( $post_id ) {
            // $way         } elseif ( isset( $urltest['path'] ) && preg_match( '#p/[0-9]{1,}#', $urltest['path']$match ) ) {
            // The path defines the post_ID (archives/p/XXXX).             $blah    = explode( '/', $match[0] );
            $post_id = (int) $blah[1];
        } elseif ( isset( $urltest['query'] ) && preg_match( '#p=[0-9]{1,}#', $urltest['query']$match ) ) {
            // The query string defines the post_ID (?p=XXXX).             $blah    = explode( '=', $match[0] );
            $post_id = (int) $blah[1];
        }
public function __construct(
        private readonly ContainerInterface $scheduleProviders,
        private readonly ClockInterface $clock = new Clock(),
    ) {
    }

    public function createTransport(string $dsn, array $options, SerializerInterface $serializer): SchedulerTransport
    {
        if ('schedule://' === $dsn) {
            throw new InvalidArgumentException('The Schedule DSN must contains a name, e.g. "schedule://default".');
        }
        if (false === $scheduleName = parse_url($dsn, \PHP_URL_HOST)) {
            throw new InvalidArgumentException(sprintf('The given Schedule DSN "%s" is invalid.', $dsn));
        }
        if (!$this->scheduleProviders->has($scheduleName)) {
            throw new InvalidArgumentException(sprintf('The schedule "%s" is not found.', $scheduleName));
        }

        /** @var ScheduleProviderInterface $scheduleProvider */
        $scheduleProvider = $this->scheduleProviders->get($scheduleName);

        return new SchedulerTransport(new MessageGenerator($scheduleProvider$scheduleName$this->clock));
    }

    
if (str_starts_with($key, 'http-')) {
        $headers[substr($key, 5)] = $val;
      }
      // CONTENT_* are not prefixed with HTTP_       elseif (isset($content_headers[$key])) {
        $headers[$key] = $val;
      }
    }

    $cookies = CookieJar::fromArray(
      $this->getCookieJar()->allRawValues($request->getUri()),
      parse_url($request->getUri(), PHP_URL_HOST)
    );

    $request_options = [
      'cookies' => $cookies,
      'allow_redirects' => FALSE,
    ];

    if (!\in_array($request->getMethod()['GET', 'HEAD'], TRUE)) {
      if (NULL !== $content = $request->getContent()) {
        $request_options['body'] = $content;
      }
      
<?php declare(strict_types=1);

namespace Shopware\Core\Content\Media\File;

use Shopware\Core\Framework\Log\Package;

#[Package('buyers-experience')] class FileUrlValidator implements FileUrlValidatorInterface
{
    public function isValid(string $source): bool
    {
        $host = parse_url($source, \PHP_URL_HOST);
        if ($host === false || $host === null) {
            return false;
        }

        $ip = gethostbyname($host);

        if (str_contains($ip, '[')) {
            return $this->validateIpv6(trim($ip, '[]'));
        }

        return $this->validateIpv4($ip);
    }

        if ( ! str_ends_with( $url, 'index.php' ) ) {
            $url .= 'index.php';
        }

        $url = add_query_arg( 'rest_route', $path$url );
    }

    if ( is_ssl() && isset( $_SERVER['SERVER_NAME'] ) ) {
        // If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS.         if ( parse_url( get_home_url( $blog_id ), PHP_URL_HOST ) === $_SERVER['SERVER_NAME'] ) {
            $url = set_url_scheme( $url, 'https' );
        }
    }

    if ( is_admin() && force_ssl_admin() ) {
        /* * In this situation the home URL may be http:, and `is_ssl()` may be false, * but the admin is served over https: (one way or another), so REST API usage * will be blocked by browsers unless it is also served over HTTPS. */
        $url = set_url_scheme( $url, 'https' );
    }
public $error;

    /** * @param string $server * @param string|false $path * @param int|false $port * @param int $timeout */
    public function __construct( $server$path = false, $port = false, $timeout = 15 ) {
        if ( ! $path ) {
            // Assume we have been given a URL instead.             $bits         = parse_url( $server );
            $this->scheme = $bits['scheme'];
            $this->server = $bits['host'];
            $this->port   = isset( $bits['port'] ) ? $bits['port'] : $port;
            $this->path   = ! empty( $bits['path'] ) ? $bits['path'] : '/';

            // Make absolutely sure we have a path.             if ( ! $this->path ) {
                $this->path = '/';
            }

            if ( ! empty( $bits['query'] ) ) {
                
 else {
                            $value = null;
                        }
                        break;
                    case Field::VALUE_TYPE_STRING:
                    default:
                        $value = $entry['value'];
                        break;
                }

                if (\in_array($entry['name']['file', 'image', 'fallback_picture'], true)) {
                    $scheme = parse_url($value, PHP_URL_SCHEME);

                    if (!\in_array($scheme['http', 'https'], true) && !\is_int($value)) {
                        $value = $this->mediaService->getUrl($value);
                    }
                }

                if (\in_array($entry['name']['selected_manufacturers', 'banner_slider'], true)) {
                    foreach ($value as $k => $v) {
                        if (isset($v['path'])) {
                            $value[$k]['path'] = $this->mediaService->getUrl($v['path']);
                        }
                    }
/** * {@inheritdoc} * * This is a helper function that calls buildExternalUrl() or buildLocalUrl() * based on a check of whether the path is a valid external URL. */
  public function assemble($uri, array $options = []$collect_bubbleable_metadata = FALSE) {
    // Note that UrlHelper::isExternal will return FALSE if the $uri has a     // disallowed protocol. This is later made safe since we always add at     // least a leading slash.     if (parse_url($uri, PHP_URL_SCHEME) === 'base') {
      return $this->buildLocalUrl($uri$options$collect_bubbleable_metadata);
    }
    elseif (UrlHelper::isExternal($uri)) {
      // UrlHelper::isExternal() only returns true for safe protocols.       return $this->buildExternalUrl($uri$options$collect_bubbleable_metadata);
    }
    throw new \InvalidArgumentException("The URI '$uri' is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.");
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.