0

I am developing a news website and i wanted to limit the number of words in $ row ['text'] but I am not able to. Could you help me? Thank you.

<?php          
        if(mysqli_num_rows($result) > 0){
            while($row = mysqli_fetch_array($result)){
                echo "<div class='container' id='fadein2'>";
                    echo "<div class='row'>";
                        echo "<div class='col-sm-3'>";
                             echo "<a href='admin_destaques_noticia.php?id={$row['id']}'><img src='upload/destaques/{$row['image']}' id='imagem' class='imagem img-fluid'></a>";
                        echo "</div>";
                        echo "<div class='col-sm-9'>";
                            echo "<a href='admin_destaques_noticia.php?id={$row['id']}' id='url_sem_linha'><p class='destaques_lista'>{$row['titulo']}</p></a>";
                            echo "<a href='admin_destaques_noticia.php?id={$row['id']}' id='url_sem_linha'><p class='destaques_lista'>{$row['texto']}</p></a>";
                            echo "<a href='admin_destaques_noticia.php?id={$row['id']}' id='url_sem_linha'><p class='ler_noticia'>Clique para ler a notícia</p></a>";
                            echo "<p></p>";
                        echo "</div>";
                        echo "<div class='col-sm-6' align='right'><a href='admin_destaques_editar.php?update_id={$row['id']}' class='btn btn-warning'>Editar</a></div>";
                        echo "<div class='col-sm-6'><a href='?delete_id={$row['id']}' class='btn btn-danger'>Eliminar</a></div>";
                    echo "</div>";
                echo "<div class='linha_paginas'></div>";
                echo "</div>";
                echo "<p></p>";
            }
        } else{
            echo"<h2>Não existe</h2>";
        }
    ?>
  • Where are you trying to achieve that in your code ? – Cid May 22 '19 at 13:24
  • 2
    I don't see any attempt of limiting any text in the posted code. Please show us what you've tried, the expected result and what result you're getting. – M. Eriksson May 22 '19 at 13:24
  • I did try to use the code from boarder https://stackoverflow.com/questions/7421134/limiting-the-output-of-phps-echo-to-200-characters/35098007. but without any luck – Lucas Santos May 22 '19 at 13:26
  • U can use split function to split your string by space, then u can get first how many words u want to get – Farhad Misirli May 22 '19 at 14:46

1 Answers1

-1

You can use the substr function to limit the string to a certain number of characters.