We are posting to Instagram; line breaks work one way (js), but don't work when processed server-side (php): why is this?
We have created a server side app that creates and schedules posts with Hootsuite, and we post with Twitter, Instagram and Facebook.
Say if this were the post:
I am line 1.
I am line 2.
I am ine 3.
It will be sent to Hootsuite and then posted to the appropriate platform; it appears like that on Twitter and Facebook. However when posting to Instagram, it appears as such:
I am line 1.I am line 2.I am line 3.
Line breaks are ignored (not always the case, but the first few certainly are).
We have noticed that if we send the post to Hootsuite, and prior to publishing, we run the text through this: it fixes the problem.
Below are the two ways that line breaks are being introduced: (php for our app, js for the linked website)
<?php
// outputted wherever line breaks are necessary
$output .= "I am string \r\nEnd of string";
?>
<script>
// Example using the copyToClipboard() function from http://apps4lifehost.com/Instagram/CaptionMaker.html
var str = "I am text
End of string";
str.replace(/(?:\r\n|\r|\n)/g, "\u2063\n");
</script>
The php method of inserting breaks works for all other platforms, and in the Hootsuite preview, but then doesn't work once posted to instagram. However the JS one does.
We need to use the PHP method to make the process more efficient, so how can we do this?
Sorry if information is lacking; the project is confidential, so we can provide more information if necessary: please just ask and I will edit the question.
Instagram removes line-breaks by default, not only via API, but even when you manually type a caption through their app.
You can get around this by using special characters instead of standard line-breaks, like the INVISIBLE SEPARATOR (U+2063)
. If you take a look at the JavaScript solution in your question, they are replacing their line-breaks with "\u2063\n"
(Invisible Separator, Line Feed).
I'd imagine you could replicate that in your PHP, based on this answer.
<?php
$output = "I am line 1 \u{2063}\n I am line 2";
?>