I have some api pattern url with params:
http://api.example.com/{type}/{function}?{parameters}&lang={lang}&authkey={authkey}&username={username}
What is the best way to replace params for values, maybe some magic class there is?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you dont need to use magic for simple task like this.
Just use
str_replaceto replace “{function}” (in that “template”) with some variable value.For {parameters}, which can be multiple you may write small function that puts these parameters into one variable and makes something like this:
¶m_1=value1¶m_2=value2from array like this:$parameters = array("param_1" => "value 1", "param_2 => "value 2");Maybe something like this:
I hope you get the idea.