Jump to content

Limited Words


rareyush
 Share

Recommended Posts

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

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 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...