php - How I have to encode url for Facebook sharing


I am using a JScript code like this:

shareLink = function (link) {

        method: 'share',
        display: 'popup',
        href: link,
    }, function(response){});


and it is called in a line like this:

$sharedata = " ... parameters ... "

<a href="javascript:shareLink('http://<?php echo $site; ?>/?v=<?php echo rawurlencode($sharelink); ?>');">

so, the destination script trasform parameter by using:

$str = rawurldecode($_GET["v"]);

the problem is when the url has a "+" character
using rawurlencode it its converted to "%2B"


but facebook change only "%2B" into "+" sign again:


and my script does not recognize it


if I echo the "v" parameter I get

zcu0xci/FMH2 7cLDPVP gD7/wQJ/FT2Bw==

instead of



the solution I've found is to replace space by "+" before decode

$str = str_replace(" ","+",$str);



You don't need to userawurldecode() on elements of the$_GET super-global variable. PHP decodes URL data for you.

In addition, you should generally useurlencode() to encode query string data. If you investigate the difference between these two functions, you'll see that urlencode() will translate any space character to the "+" character. This could possibly be the problem you're experiencing.

I'm having difficulty understanding the remainder of your question. You may need to work on your phrasing.

People are also looking for solutions to the problem: php - Composer create project issue


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.