Backend\Modules\Pages\Engine\Model::getEncodedRedirectURL PHP Method

getEncodedRedirectURL() public static method

Get encoded redirect URL
public static getEncodedRedirectURL ( string $redirectURL ) : string
$redirectURL string
return string
    public static function getEncodedRedirectURL($redirectURL)
    {
        preg_match('!(http[s]?)://(.*)!i', $redirectURL, $matches);
        $URLChunks = explode('/', $matches[2]);
        if (!empty($URLChunks)) {
            // skip domain name
            $domain = array_shift($URLChunks);
            foreach ($URLChunks as &$URLChunk) {
                $URLChunk = rawurlencode($URLChunk);
            }
            $redirectURL = $matches[1] . '://' . $domain . '/' . implode('/', $URLChunks);
        }
        return $redirectURL;
    }

Usage Example

Example #1
0
 public function testUrlIsEncoded()
 {
     self::assertEquals('http://www.google.be/Quote', Model::getEncodedRedirectURL('http://www.google.be/Quote'));
     self::assertEquals('http://www.google.be/Quote%22HelloWorld%22', Model::getEncodedRedirectURL('http://www.google.be/Quote"HelloWorld"'));
     self::assertEquals('http://www.google.be/Quote%27HelloWorld%27', Model::getEncodedRedirectURL("http://www.google.be/Quote'HelloWorld'"));
     self::assertEquals('http://cédé.be/Quote%22HelloWorld%22', Model::getEncodedRedirectURL('http://cédé.be/Quote"HelloWorld"'));
 }
All Usage Examples Of Backend\Modules\Pages\Engine\Model::getEncodedRedirectURL