首页 > 解决方案 > 如何在使用 php 之前更改 url

问题描述

我有一个下载解析器的功能,其中一个站点的 URL 已更改: http: //paste.cohttps://controlc.com/

我无法从数据库更改 url,因为 a 已加密。

class download_parser

{   
    private $container_domains  = '(?:tinypaste\\.com|tny\\.cz|controlc\\.com)';
    private $base_url           = '';
    private $package            = null;
    private $package_passwords  = array();
    public $current_password    = '';

    public function __construct()
    {
        global $phpbb_root_path, $phpEx;
        include($phpbb_root_path . 'contributions/dlcapi/dlcapi.class.' . $phpEx);
    }

    public function set_base_url($url)
    {
        $this->base_url = preg_replace('#http[s]?://#i', '', $url);
        if(substr($this->base_url, -1) != '/')
        {
            $this->base_url .= '/';
        }
        return $this;
    }

在解密容器之前,我需要帮助将旧网址(pased.co)更改为新网址。

标签: phpurlpreg-replace

解决方案


利用preg_replace

    public function set_base_url($url)
    {
        $this->base_url = preg_replace('#http[s]?://#i', '', $url);
        $this->base_url = preg_replace('#^paste\.co\b#', 'controlc.com', $this->base_url);
        if(substr($this->base_url, -1) != '/')
        {
            $this->base_url .= '/';
        }
        return $this;
    }

推荐阅读