The source of char_limit.php (click to demo the file) viewed 1540 times.
If I wrote this code, then it is licensed under the GPL. If someone else wrote it, then please ask them if you want to use the code.
<?php
// set variable
$var = "Hello, this is going to be longer that 50 letters long which isn't that hard!!!!";
// display normal variable
echo "Display normal variable: <b>".$var."</b><br><br>";
// count number of characters
$varlength = strlen($var);
// set character limit
$limit = 50;
// if character number if more than character limit
if ($varlength > $limit) {
// display string up to character limit, add dots
$var = substr($var,0,$limit)."...";
}
// display variable
echo "Display edited variable: <b>".$var."</b>";
?>
If you want to have a look at the source code, chose a file from this list:
To colour code your own PHP paste it here: