Skip to main content

How to Add Three Dots to a Long String PHP

How to Add Three Dots  to a Long String  PHP



 Hello friends , today we learn how to add three dots at the end of a string if string length is greater then limit.
so this is the code we are using to add three Ellipsis with PHP.

<?php
//$content = Your String.
$content = substr($content, 0, 500);
$content = substr($content, 0, strrpos($content, ' ')) . " ...";

?> 

here we are using substr and strrpos functions. the substr function returns a part of a string and we are Using the start and length parameters (0,500).
 

 and the second function strrpos , The strrpos() function finds the position of the last occurrence of a string inside another string. and the syntax of strrpos is-

Syntax - strrpos(string,find,start)

Comments

Post a Comment