PHP: passing php variables as arguments?
725
In my php code I need to invoke a script and passing it some arguments. How can I pass php variables (as arguments) ?
$string1="some value";
$string2="some other value";
header('Location: '...script.php?arg1=$string1&arg2=$string2');
thanks
Answer
Solution:
Answer
Solution:
Either via string concatenation:
Or string interpolation
Personally, I prefer the second style. It's far easier on the eyes and less chance of a misplaced quote and/or
.
, and with any decent syntax highlighting editor, the variables will be colored differently than the rest of the string.The urlencode() portion is required if your values have any kind of url-metacharacters in them (spaces, ampersands, etc...)
Answer
Solution:
You could use the function http_build_query
Answer
Solution:
Like this:
Answer
Solution:
It should work, but wrap a urlencode() incase there is anything funny breaking the url: