Question:
How to add a Parsing PHP file in order to get an array of parameters?

To create a parsing PHP file that extracts parameters and returns them as an array, you can use the Tokenizer to retrieve parameters passed in the URL or through a POST request. Additionally, you may use functions like filter_input() for better validation and filtering of input.


<?

$tokens = token_get_all();


$componentName = "hoo:account";


$arParams = array();


foreach ($tokens as $tokenKey => $token) {

    if (is_array($token)) {

        if (_getTokenName($token) == "T_STRING" &&

            _getToken($tokens, $tokenKey + 3) == $componentName

        ) {

            $isComponent = true;

        } elseif (_getTokenName($token) == "T_STRING" &&

                  _getToken($tokens, $tokenKey + 3) != $componentName

        ) {

            $isComponent = false;

        }


        if ($isComponent) {

            if (_getTokenName($token) == "T_DOUBLE_ARROW") {

                if (_getTokenName($tokens[$tokenKey - 2]) == "T_CONSTANT_ENCAPSED_STRING") {

                    if (_getTokenName($tokens[$tokenKey + 2]) == "T_ARRAY") {

                        $key = _getToken($tokens, $tokenKey - 2);

                    } else {

                        $arParams[_getToken($tokens, $tokenKey - 2)] = _getToken($tokens, $tokenKey + 2);

                    }

                } elseif (_getTokenName($tokens[$tokenKey - 2]) == "T_LNUMBER") {

                    $arParams[$key][] = _getToken($tokens, $tokenKey + 2);

                }

            }

        }

    }

}


function _getTokenName(array $token): string {

    return token_name($token[0]);

}


function _getToken(array $tokens, int $key): int | string {

    return trim($tokens[$key][1], "\"");

}

?>


Answered by:> Viacheslav Ravdin

Credit:> Stackoverflow


Suggested Blogs:

>Plugins and Presets for Vuejs project

>Use of Singletons in .NET Core in AWS Lambda

>Ways to repair the .NET Framework on Windows

>How to Create a project using Vue.js for beginners?


Ritu Singh

Ritu Singh

Submit
0 Answers