How to insert a variable in a GET request using echo?

PHP sends a request
echo '<img src="work.php? met=384 &amp; hour=19 &amp; post=false" />';

Everything is OK, everything works. Trying to insert instead of numbers the variable $str. All at once a mistake. Seem to have tried everything, I can detail what is missing? There is probably some solution? Thanks in advance.
March 19th 20 at 08:24
3 answers
March 19th 20 at 08:26
Maybe something like that
echo '<img src="work.php?met=' . $str . '&amp;hour=' . $str . '&amp;post=false" />';
echo "<img src=\"work.php?met={$str}&amp;hour={$str}&amp;post=false\" />";
The option
echo '<img src="work.php?met=' . $str . '&amp;hour=' . $str . '&amp;post=false" />';

worked. Thank you very much!!!! - marian_Schmele commented on March 19th 20 at 08:29
March 19th 20 at 08:28
$imgSrc = 'work.php';
$imgSrc .= '?' . http_build_query(['met' => 384, 'hour' => 19, 'post' => 'false', 'str' => $str]);
echo '<img src="'. $imgSrc .'" />';
Thank you, for the future, this option will use too!!! - marian_Schmele commented on March 19th 20 at 08:31
March 19th 20 at 08:30
The most important answer why it happened. And due to the fact that the treatment variables only inside double quotation marks. Respectively, or a line or concatenation.

Find more questions by tags PHP