I am modifying a piece of code, the essence is to pick the first 90 characters from the body of a post. I have managed to get the text including some punctuation characters.
My problem is that I do not know how to get the 90 characters NOT to ignore newline. I want it to terminate once it encounters a line break. As it is now, it doesn’t respect it and so ends up adding content from another line/paragraph.
This is the code I am using –
$title_data = substr($postdata,0,90);
$title_data = preg_replace("/[^w#&,":; ]/",'', strip_tags($title_data));
$data['post_title'] = "F. Y. I - " . $title_data . " ...";
The right first step you do the preg_replace(), then you put that value to substr() param.
Here’s my to cents… It also makes sure words aren’t truncated.
A bit more complicated, but might help to get the result you’re after: