4

I have link which needs to be shared in whatsapp which looks like the one shown below.

<?php 
$temp = 'whatsapp://send?text=http://www.example.com/index.php?
           secid=1&url=/content/575098/ready-opposed.html';
?>

<a href="<?php echo urlencode($temp); ?>">
  <img src="img_uploads/watsapp.png" width="18" height="18"/>
</a>  

So now when I share it through mobile site, in Whatsapp I get only http://www.example.com/index.php?secid=1 but the next parameter url is not there. Just to test if I put url as 1st parameter and secid as 2nd parameter then I receive only url but not secid.

In my scenario only if those 2 parameters is present the page is rendered

Can someone please help me solve this issue.

Sharath
  • 2,348
  • 8
  • 45
  • 81

3 Answers3

5

Just Use The rawurlencode() instead of urlencode() For example

<?php
$value = 2;
$text = rawurlencode("www.domain.com/products.php?Id=".$value);
?>
<a href="https://api.whatsapp.com/send?text=<?php echo $text; ?>"><i class="fa fa-whatsapp"></i></a>
Vikas Jangra
  • 175
  • 2
  • 9
4

I'm reviving an old/dead answer, but I had the same problem and solved URLencoding the special chars.

In this case, convert the & with %26

Some ref:

Pixel88
  • 41
  • 3
1

I solved a similar problem using:

$value = 2;
$message_to_send = urlencode(rawurlencode("www.domain.com/products.php?Id=".$value))
Dharman
  • 30,962
  • 25
  • 85
  • 135