Descobrindo a quantidade de quebra de linhas de um texto com PHP
Olá pessoal, como vocês estão?! Em minhas navegações e pesquisas pela web, me deparei com uma dúvida postada no Stack Ovwerflow, sendo a seguinte: Como posso descobrir quantas linhas tem um texto?” Na descrição da dúvida, foi explicado que o objetivo era contar quantas quebras de linhas tem em um texto. Sabendo da dúvida, agora vamos em busca da resposta. 1 2 3 4 5 6 7 <?php $string = 'Bacon ipsum dolor amet fatback sausage ball tip ham hock bacon burgdoggen. Pancetta ham hock frankfurter swine sausage tenderloin, kevin short ribs. Sirloin filet mignon meatball ham, ham hock cow prosciutto rump ground round brisket. Jowl short loin frankfurter pork chop ball tip rump shank kevin shoulder short ribs andouille. Turducken beef ribs corned beef, meatball shankle hamburger andouille shank short ribs sausage leberkas. Porchetta hamburger shank, pork loin spare ribs tail cupim meatloaf. Strip steak ground round flank doner pork sirloin. Tri-tip spare ribs swine, ground round ribeye salami pancetta cupim pig beef. Pork chop chicken doner picanha. Strip steak ribeye short loin, pancetta tri-tip rump fatback corned beef meatloaf alcatra kevin drumstick. Bresaola shoulder shank, rump ham ground round strip steak t-bone.'; $lines = substr_count( nl2br($string), '<br />'); E como retorno teremos “2” bem simples, porém vamos detalhar um pouco o código. ...