SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Mar 28, 2008, 22:27 #1
How to count how many characters in a paragraph?
I want to be able to count how many characters are in a paragraph excluding whitespace. Anybody help me?
-
Mar 28, 2008, 22:34 #2
- Join Date
- Mar 2008
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Mar 28, 2008, 22:40 #3
- Join Date
- Sep 2007
- Posts
- 371
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here you go :
PHP Code:$para = <<<EDT
This is just a test paragraph.
Second line in the test paragraph.
Third line in the test paragraph.
EDT;
$new_para = preg_replace('/\s+/','', $para);
echo strlen($new_para);
-
Mar 29, 2008, 07:03 #4
-
Mar 29, 2008, 07:10 #5
-
Mar 29, 2008, 08:12 #6
- Join Date
- Feb 2007
- Location
- UK
- Posts
- 591
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you want to keep most of the whitespace (spaces newlines etc), you can use trim($var) to get rid of whitespace only at the start and end of the string.
Bookmarks