Aizaz Barki
Aizaz Barki

Reputation: 93

Facebook share not working with line breaks, whitespace, single quotes and double quotes in text

I want to share text in Facebook through the Facebook JavaScript SDK.

So when it is normal text, share is working correcty when I include a whitespace, line break, single quote or double quote. It creates a problem. What should I do to remove such a situation?

As I am retrieving data from a database which might be included with all these spaces, line breaks, single quotes, double quotes or slashes.

FB.ui({
    method      : 'stream.publish',
    name        : 'Application Name or some thing else',

    picture     :  'http://example.com/first.jpg',
    caption     : 'I want to upload this caption to facebook',
    link        :    'http://www.example.com',
    description : 'I don't want to hide "Facebook page" from any user.
    This is like text is not working. What might be the reason, and what should I do?
    '
});

What technique should I apply to be safe from a wrong posting? It must accept special characters.

Upvotes: 2

Views: 1844

Answers (3)

Aizaz Barki
Aizaz Barki

Reputation: 93

I have written a JavaScript function for this problem. It worked great for me.

function stripslashes (str)
{
    return (str + '').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\u0000';
            case '':
                return '';
            default:
                return n1;
        }
    });
}

Upvotes: 1

Luca Simonetti
Luca Simonetti

Reputation: 127

I don\'t

You need to correct this in that snippet. Obviously every ' (single quote) should become \'

This is ABC :)

Upvotes: 1

geoffreys
geoffreys

Reputation: 1117

Have you tried HTML or URL encoding the text? I'm not a PHP developer but this seems relevant www.php.net/manual/en/function.htmlspecialchars.php

Upvotes: 0

Related Questions