Search code examples
phpyiiyii-url-manager

How to url-decode a URL in Yii?


How to parse the URL which in the format as shown

http://localhost/CorrectCodeToDeploy/healthkatta/index.php?r=site%2FArticle%2F2013%2F07%2F13%2FDisadvantages-of-smoking-51e12690a5a58

I want to get rid of the special characters %2F and put / instead.

I have shared a link of an article to Facebook
but when I access this link from Facebook it comes in the format as mentioned above and the content is not properly accessed in Yii. How can I write the pattern to access this kind of URL in Yii?


Solution

  • Maybe you can directly decode your $_GET in your index.php file, something like:

    $_GET = array_map('urldecode', $_GET);
    

    Please be aware the above doesn't work with nested arrays, so you need to create a more in depth recursive function like (not tested though) :

    function urldecodeArray($strArr){
        if (!is_string($strArr) && !is_array($strArr)) {
           return $strArr;
        }
        if(is_string($strArr)) {
            return urldecode($strArr);
        }
        foreach ($strArr as $key=>$value) {
           $strArr[$key] = urldecodeArray($value);
        }
        return $strArr;
    }
    $_GET = urldecodeArray($_GET);