I have used PHP, json and API Cache to successfully show a Facebook Feed Message on a website. However some of the messages are too long to fit into the space provided on the website.
Does anyone know if there is a way to limit the amount of Words or Characters the message will display?
Best scenario would to have the message show fully if below limit and then show certain amount of words or characters i over followed by [...] read full post @pagename
Then I can add the link to the Facebook post to view full message. I know how to add the post link and text, just need to scale the message down.
Here is the PHP code I am using:
<?php $fb_message = $fb_json->data[0]->message; ?>
<?php echo $fb_message; ?>
Any help would be greatly appreciated.
Thanks, Steve
Thanks to James Pearce I was able to get it working using the following code:
<?php $fb_message = $fb_json->data[0]->message; $truncated = substr($fb_message, 0, strrpos(substr($fb_message, 0, 100), ' ')); echo $truncated . '...'; ?>
It works if the message is more than 100 characters, but if it is less it will only show the first word and no more....?
Anyone know what I am doing wrong?