PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] how to change an url before to use on php

 November 20, 2022     php, preg-replace, url     No comments   

Issue

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.


Solution

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


Answered By - Barmar
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing