Is there any way to limit characters in echo $row-> variable in codeigniter

StackOverflow https://stackoverflow.com/questions/23677232

  •  23-07-2023
  •  | 
  •  

Вопрос

I am currently developing a CMS and want to add in the functionality of limiting an excerpt of text by its line length. Say I want to control the display of text and ensure all blocks are the same height by controlling the amount of lines of text that show.I am using for each to display inbox function message data. In the message section it shows full message and I want to limit it into 30

<?php

if(isset($records)) :
foreach($records as $row) :
?>
                <tr >
                    <td class="right"><?php  echo $row->contactus_name; ?></td>
                    <td class="right"><?php  echo $row->contactus_email; ?></td>
                    <td class="right"><?php  echo $row->contactus_phone; ?></td>
                    <td class="right tertiary-text-secondary text-justify"><?php  echo $row->contactus_comment; ?></td>
                </tr>
            <?php  endforeach; ?>
            </tbody>
            <tfoot></tfoot>
        </table>
        <?php else : ?>
            <p>No records</p>
        <?php  endif; ?>
Это было полезно?

Решение 2

//IN CONTROLLER

$this->load->helper('text');

<?php echo word_limiter($row->contactus_comment,30); ?>

Другие советы

If you include the text helper in your controller:

$this->load->helper('text');

or in autoload.php:

$autoload['helper'] = array('url', 'form', 'html', 'text');

You can then use word_limiter().

From the documentation:

$string = "Here is a nice text string consisting of eleven words.";

$string = word_limiter($string, 4);

// Returns: Here is a nice…

There is also character_limiter() which works the same way. Again, from the documentation:

$string = "Here is a nice text string consisting of eleven words.";

$string = character_limiter($string, 20);

// Returns: Here is a nice text string…
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top