rareyush Posted November 26, 2017 Share Posted November 26, 2017 I'm trying to display body part but as a summary which doesn't include any image. I was able to get limit the words by using this function <?PHP function truncateWords($input, $numwords, $padding="") { $output = strtok($input, " \n"); while(--$numwords > 0) $output .= " " . strtok(" \n"); if($output != $input) $output .= $padding; return $output; } ?> but if there is an image it show that image as well. any api or anything which I can use to use show just limited text ????? Link to comment Share on other sites More sharing options...
rafaoski Posted November 26, 2017 Share Posted November 26, 2017 Welcome to the forum @rareyush ... Sanitizer can help in this case which cleans up the text.https://processwire.com/api/variables/sanitizer/https://processwire.com/api/ref/sanitizer/https://processwire.com/api/ref/sanitizer/text/ Try the following: $p_body = $sanitizer->text($key->body,['maxLength' => 250]); echo "<p>{$p_body}</p>"; 2 1 Link to comment Share on other sites More sharing options...
Zeka Posted November 26, 2017 Share Posted November 26, 2017 Take a look at this blog post https://processwire.com/blog/posts/pw-3.0.28/ 3 1 Link to comment Share on other sites More sharing options...
rareyush Posted November 27, 2017 Author Share Posted November 27, 2017 16 hours ago, rafaoski said: Welcome to the forum @rareyush ... Sanitizer can help in this case which cleans up the text.https://processwire.com/api/variables/sanitizer/https://processwire.com/api/ref/sanitizer/https://processwire.com/api/ref/sanitizer/text/ Try the following: $p_body = $sanitizer->text($key->body,['maxLength' => 250]); echo "<p>{$p_body}</p>"; This worked for me, Thank you I really appreciate and this is why I love processwire more now xD 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now