Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line in twitter API abraham\TwitterOAuth

After implementing the necessary changes to support emojis into my database I have came across this problem where I can't seem to fit a new line into posting a new tweet to Twitter.

Lets suppose I have the following code:

$parameters = [
    'status'    => "Foo. \n New line",
];

Twitter will render it correctly since it is in ". If I happen to do the following:

$parameters = [
    'status'    => 'Foo. \n New line',
];

Twitter will render Foo. \n New Line.

My questions starts when I need to update the status with a new line terminator \n in it.

$tweet = $dataFromDatabase;
$parameters = [
    'status' => $tweet
]

Twitter will render the literal string coming from the database (which in this example we can suppost it is Foo. \n New Line).

I suppose the problem comes from using ' instead of ".

Question

How I can make Twitter read the $tweet variable correctly displaying the content formated correctly?

I have tried the following solutions without success:

$parameters = [
    'status'    => '"'. $tweet .'"',
];
$parameters = [
    'status'    => addslashes($tweet),
];
$parameters = [
    'status'    => "{$tweet}",
];
like image 998
null Avatar asked Oct 16 '25 09:10

null


1 Answers

If you want to publish a new message with line breaks, in PHP, the code is:

$parameters = array("status" => "Content of the first line" . chr(13) . chr(10) . "Content of the second line");
like image 61
xavigs1984 Avatar answered Oct 18 '25 05:10

xavigs1984



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!