Is there any way to echo '&timestamp' in php? [duplicate]

Code:

function getShopInfo()
    {
        $url = $this->env['url'] . "shop/get?partner_id=" . $this->partner_id . "&shopid=" . $this->shop_id . "&timestamp=" . $this->getTimestamp();
        echo $url;
    }

Result:

https://url.com/api/v2/shop/get?partner_id=99999&shopid=123456×tamp=1613629442

Why the output for &timestamp is printed as ×tamp?


& has special meaning in HTML, it's used to start an entity specification.

Use the htmlspecialchars() function to encode all the special characters so you can see them literally.

echo htmlspecialchars($url);

Better yet, you should be using http_build_query() to build URL-encoded query strings. i.e:

function getShopInfo()
{
    $data = [
        "partner_id" => $this->partner_id,
        "shopid" => $this->shop_id,
        "timestamp" => $this->getTimestamp()
    ];

    $url =  $this->env['url'] . "shop/get?". http_build_query($data);
    echo $url;
}