Reputation: 23989
I have the follwing two PHP variables to build a string which when complete will be a url to post to Twitter:
$encUrl = 'http://example.com/wish/'.str_replace(' ','-',$id[item_title]).'/'.$id[wish_id];
$encTitle = urlencode($id[item_title]);
$tweetTo = "https://twitter.com/share?url=$encUrl&text=$encTitle&via=myTwitter";
Then within javascript I'm trying:
window.open("<?=$tweetTo?>","","width=600,height=450");
When the page is rendered though it breaks by adding a line break e.g.
window.open(https://twitter.com/share?url=http://example.com/wish/Antique-earrings
/11786&text=Antique+earrings%0D%0A&via=myTwitter,"","width=600,height=450");
The error is
unterminated string literal
window.open("https://twitter.com/share?url=http://example.com/wish/Antiq
Is there a way around this?
Upvotes: 0
Views: 46
Reputation:
@Darren. You are also required to encode $encUrl
. Browser or any other scripting language will not understand URL inside URL.
https://twitter.com/share?url=http://example.com/wish/Antique-earrings
The part after url=
( which is http://example.com/wish/Antique-earrings ) must be encoded.
Hope that helps. Please let me know in case of more issues.
Upvotes: 2