Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $listString = $_GET['list'];
- $maxSize = $_GET['maxSize'];
- $listItems = preg_split('/\s{2}/', $listString, -1, PREG_SPLIT_NO_EMPTY);
- echo "<ul>";
- foreach ($listItems as $item) {
- if (strlen($item) <= $maxSize) {
- // Small items stay unchanged
- $text = htmlspecialchars($item);
- } else {
- // Long items get truncated
- $text = htmlspecialchars(substr($item, 0, $maxSize)) . "...";
- }
- echo "<li>$text</li>";
- }
- echo "</ul>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement