PHP sprintf () Error of arguments when placing a url with Whatsapp

0

I am placing a WhatsApp URL in PHP in the following code:

$url = "https://api.whatsapp.com/send?phone=57xxxxxxxx&text=Bienvenido%20a%20xxxxxx,%20estas%20interesado%20en%20el%20Tartar%20de%20Atun%20";
$link = sprintf( '<a href="'.$url.'" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="whatssapp">Pídelo ahora</a>');

But I get the following error:

  

sprintf (): Too few arguments in C: \ xampp \ htdocs \ elmandadito \ wp-content \ themes \ online-shop \ functions.php

When I change the URL with https://www.google.com.co it works fine.

    
asked by Carlos Cespedes 06.11.2018 в 17:23
source

1 answer

1

You must enter the URL as parameter %s of sprintf since your URL contains characters that define the format (zones that contain the character % ), so sprintf complains about having defined gaps for data that you have not filled in with the corresponding parameters:

$url = "https://api.whatsapp.com/send?phone=57xxxxxxxx&#038;text=Bienvenido%20a%20xxxxxx,%20estas%20interesado%20en%20el%20Tartar%20de%20Atun%20";
$link = sprintf(
  '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="whatssapp">Pídelo ahora</a>',
  $url,
  htmlspecialchars($id),
  htmlspecialchars($sku),
  htmlspecialchars($cantidad)
);
    
answered by 06.11.2018 / 17:36
source