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}",
];
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");