Advertisement
felix_de_suza

Exam problem 1

Aug 31st, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. <?php
  2. $listString = $_GET['list'];
  3. $maxSize = $_GET['maxSize'];
  4.  
  5. $listItems = preg_split('/\s{2}/', $listString, -1, PREG_SPLIT_NO_EMPTY);
  6. echo "<ul>";
  7. foreach ($listItems as $item) {
  8. if (strlen($item) <= $maxSize) {
  9. // Small items stay unchanged
  10. $text = htmlspecialchars($item);
  11. } else {
  12. // Long items get truncated
  13. $text = htmlspecialchars(substr($item, 0, $maxSize)) . "...";
  14. }
  15. echo "<li>$text</li>";
  16. }
  17. echo "</ul>";
  18. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement