facebook sharer url中的“&”字符

My site has urls like

$shareurl = http://www.mysite.com/?view=main&title=here-is-some-title  

So if i put this url in facebook and twitter sharer links appear like below

facebook sharer url:

<a target="_blank" href="https://www.facebook.com/dialog/feed?app_id=MY_APP_ID&link=<?php echo $shareurl;?>&picture=Picture.jpg&name=this is name&caption=this is caption&description=this is despcription.&redirect_uri=<?php echo APP_BASE_URL; ?>""> Share on Facebook </a>

& character into $sharerurl splits the facebook sharer url. The situation is same in Twitter.
How can i avoid from this condition by simplest way?

If you use this code you should be fine:

<a target="_blank" href="https://www.facebook.com/dialog/feed?app_id=MY_APP_ID&link=<?php echo urlencode($shareurl);?>&picture=Picture.jpg&name=this is name&caption=this is caption&description=this is despcription.&redirect_uri=<?php echo APP_BASE_URL; ?>""> Share on Facebook </a>

It turns the &s in the URL into %26, which Facebook & Twitter will read just fine without thinking that parts of URL are really parts of their URL.

You can encode the URL with urlencode(), then use urldecode() within your application to return the proper URL.