I'm looking for a way to limit a string in php and add on ... at the end if the string was too long.
The length of the string can be limited in PHP using various in-built functions, wherein the string character count can be restricted. Approach 1 (Using for loop): The str_split() function can be used to convert the specified string into the array object.
The maximum length of a string literal allowed in Microsoft C is approximately 2,048 bytes.
The Java String length() method is a method that is applicable for string objects. length() method returns the number of characters present in the string. The length() method is suitable for string objects but not for arrays. The length() method can also be used for StringBuilder and StringBuffer classes.
You can use something similar to the below:
if (strlen($str) > 10) $str = substr($str, 0, 7) . '...';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With