Question: I tried the sprintf function in php, but the results were not as expected, add an undesirable character:

```
https://localhost/item?item_id=abcd&redirect=https://www.google.com/×tamp=1616847526

```

unwanted is `×`

the results I expected:

```
https://localhost/item?item_id=abcd&redirect=https://www.google.com/&timestamp=1616847657

```

This is my code.

```
public function generateUrl()
{
    $url = sprintf(
        '%s%s?item_id=%s&redirect=%s&timestamp=%s',
        'https://localhost',
        '/item',
        'abcd',
        'https://www.google.com/',
        $this->timestamp,
    );
    return $url;
}

```

If I replace the `timestamp` string with something else the result will be fine. What's wrong with `timestamp`? how to solve it?

thanks.

Answer: 
Nothing is wrong with `sprintf`, `&times` is the HTML entity for the multiplication sign `x`.

If you really need to display the generated URL as you're doing now you can either use `return htmlentities($url)` instead of returning the `$url` directly, or by changing the `sprintf` call to :

```
$url = sprintf(
        '%s%s?item_id=%s&amp;redirect=%s&amp;timestamp=%s',
        'https://localhost',
        '/item',
        'abcd',
        'https://www.google.com/',
        $this->timestamp,
    );

```
To display an URL in HTML, you should use [`htmlspecialchars($url)`](https://php/.net/htmlspecialchars) to convert `&` to `&amp;`.

```
https://localhost/item?item_id=abcd&amp;redirect=https://www.google.com/&amp;timestamp=1616847657

```

Also, you could use [`http_build_query()`](https://php.net/http_build_query) to generate a **valid URL**.

```
public function generateUrl()
{
    $data = [
        'item_id'   => 'abcd',
        'redirect'  => 'https://www.google.com/',
        'timestamp' => $this->timestamp,
    ];
    return 'https://localhost/item?' . http_build_query($data);
}

```

Output:

```
https://localhost/item?item_id=abcd&redirect=https%3A%2F%2Fwww.google.com%2F&timestamp=1616849241

```