【问题标题】:how to change an url before to use on php如何在使用 php 之前更改 url
【发布时间】:2019-09-18 21:36:41
【问题描述】:

我有一个下载解析器的功能,其中一个站点的 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) 更改为新网址。

【问题讨论】:

    标签: php url preg-replace


    【解决方案1】:

    使用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;
        }
    

    【讨论】:

    • 谢谢,但没用。解析错误:语法错误,第 1 行出现意外的“download_parser”(T_STRING)
    • 那好像和我的代码无关,是类定义前的代码有问题。
    • 在类代码除了 ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多