Divide text string into sections (separate divs) of 500 characters (or any
other # of characters) using PHP?
What is the best method for taking a text string (from a mysql database,
like a wordpress post or page) and dividing the text into sections of 500
characters (or any other number of characters), and then outputting each
500-character section wrapped in its own div container?
Being new to PHP, I'm not sure how to go about segmenting the content
based on character count. We could get the character count using:
<?php
$content = get_the_content(); //wordpress function for post content as
string.
echo strlen($content);
?>
But that is as far as my knowledge goes. Can anyone help me out with this
challenge?
Let's say I was requesting a page of content from the wordpress database,
and it was 5,000 characters long. The goal would be to output 10 divs or
spans that each contained 500 characters.
THANK YOU in advance for any assistance.
No comments:
Post a Comment