PHP How to delete lines less than 6 characters long

I sort some lines and some contain email, some not.

I need to delete all lines less than 6 characters.

I surfed a bit and did not find any solid answers, so I tried to write my first expression.

Please tell me if this works. Did I understand correctly?

$six-or-more = preg_replace("!\b\w{1,5}\b!", "", $line-in); 

The following are the ones that I “stole” that may actually be redundant.

$no-empty-lines = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $six-or-more);
$lines = preg_split("/[\s]*[\n][\s]*/", $no-empty-lines);

You can see what I'm trying to do, but I think this is not much.

Thanks for the tutorial.

+3
source share
4 answers

\b " ", . , 1 5 , , . (BTW, , , , ).

$six_or_more = preg_replace('/^.{0,5}$[\r\n]*/m', '', $line_in);

/m ^ $ , . , , , , " ".

+2

strlen() mb_strlen() ( ) .

+6

, :

$lines= array('less', 'name', 'some long name', 'my.email@email.email');

, 6 ...

<?php
$lines= array('less', 'name', 'some long name', 'my.email@email.email');

foreach ($lines as $line) {
    if(strlen($line) < 6) { //this chect if string length is higher of 5
        continue; //if not skip
    }
    else {
        echo $line . '<br />'; //print line or do what you want :)
    }
}

?>

:

some long name
my.email@email.email
+2

Why not blow up the data in a new line, check to see if the length of a single line is less than 6. If it is less, cross out the line, if not, continue.

0
source

Source: https://habr.com/ru/post/1766205/