Reputation: 33
I want to share an URL via WhatsApp. Sending a normal text is working fine, but sending an URL is not working. How can I create a working WhatsApp link with an URL? I tried to do it like this, but it does not work:
<?php
$value = 2;
$productId = base64_encode($value);
?>
<a href="https://api.whatsapp.com/send?text=www.domain.com/products.php?productId=. <?php urlencode($productId) ?>">Share To WhatsApp</a>
Upvotes: 0
Views: 7034
Reputation: 195
Just Use The rawurlencode() instead of urlencode() Example
<?php
$value = 2;
$text = rawurlencode("www.domain.com/products.php?productId=".$value);
?>
<a href="https://api.whatsapp.com/send?text=<?php echo $text; ?>"><i class="fa fa-whatsapp"></i></a>
Upvotes: 2
Reputation: 817
You must encode the whole value of the text query parameter, not only the number (which doesn't do anything). Do it like that:
<?php
$value = 2;
$text = urlencode("www.domain.com/products.php?productId=".$value);
?>
<a href="https://api.whatsapp.com/send?text=<?php echo $text; ?>">Share To WhatsApp</a>
Upvotes: 2