Hommer Smith
Hommer Smith

Reputation: 27862

Find all strings that have more than 255 characters that are not whitespace in PHP

The following command will find me those strings which have more than 255 characters that are not white space.

egrep -norq '[^ ]{255,}' 

If I have a string in $content, how would I find (in PHP) all the occurrences of strings that are longer than 255 characters, and save those occurrences so that later I can echo them?

Upvotes: 1

Views: 659

Answers (1)

anubhava
anubhava

Reputation: 786041

In PHP you use preg_match for matching:

// assuming $content is your input
if ( preg_match_all('/\S{255,}/', $content , $m ) ) {
    // save $content
}
  • \S => matches any non space character
  • {255,} => makes sure there are at least 255 characters in input

Upvotes: 2

Related Questions