Skip to content
Advertisement

how to change an url before to use on php

I have a function of a download parser, where the url of one site it’s changed: http://paste.co to https://controlc.com/

I can’t change the url from a database, because aare encrypted.

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

I need help to change the old url (pased.co) to the new one, before to decrypt the container.

Advertisement

Answer

Use preg_replace

    public function set_base_url($url)
    {
        $this->base_url = preg_replace('#http[s]?://#i', '', $url);
        $this->base_url = preg_replace('#^paste.cob#', 'controlc.com', $this->base_url);
        if(substr($this->base_url, -1) != '/')
        {
            $this->base_url .= '/';
        }
        return $this;
    }
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement