How can I truncate the multiline text from the database? (html/css/php)

Viewed 59

How can I truncate the data, which I fetch from my MySQL database?

My html code:

<div class="content">
    <h3 class="title"><?php echo $title; ?></h3>
    <p class="main" id="main"><?php echo $content; ?></p>
    <a href="#"><i class="fa fa-arrow-right"></i> Artikel lesen</a>
</div>
1 Answers

If you want to truncate the value of a column, you can do that directly using the left or right function. You need to pass the amount of characters you want to get either from left or right respectively

Eg: left()

select left('left function',4) as content;

output: left

Eg: right()

select right('left function', 4) as content;

output: tion

if content is your column then you can use the following snippet:

select left(content,10) as content from <YourTableName>;
Related