C3rd
Remove Redundant Spaces, Tabs and New Lines
Posted: 8 Feb 2013, 4:43am - FridayIt's been a while that I've been dealing with long text. Commonly, users input with redundant new lines, tabs, spaces and long words. Here's my methods and just like others out there; Removing redundant new lines or line breaks:
$str = preg_replace('/(?:(?:\r\n|\r|\n)\s*){2}/s', "\n\n", $str);Removing redundant tabs:
$str = preg_replace("/[ \t]+/", " ", $str);Removing redundant spaces:
$str = preg_replace("/[ ]+/", " ", $str);Shorten long word:
function ellipsis($str, $max = 45) { if (strlen($str) > $max) { $str = '<abbr title="'.strip_tags($str).'">'.substr($str,0,$max).'...</abbr>'; } return $str; }I think that's all... Hope this will help you... :)
Search
Categories
Related Links
- Apache Web Server
- ASP Immigration Services Ltd.
- CentOS Linux
- Color Scheme Picker
- CSS Button Generator
- Deviant Art Account
- Don Tabaniag - GraphiCult
- Jerson Maglasang Weblog
- Joshua Manlunas
- Mark "mungkey" Vicente
- Matt Arnilo Baluyos
- MySQL
- Paul Labis
- PHP
- PrendStar
- Ridvan Baluyos
- Scott Davies
- SEO Fart XML-RPC Ping Tool
- Stripes Generator
- The Hero
- Ubuntu Linux
- Vim Carlo Nabora (DA)
- Wella Maria Hong
- What is my IP?
- Xavier University - Ateneo de Cagayan
- Zabyer Community