phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


String: Counting Words

Tag: String, word, count   Category: PHP Basic
post: 03 Feb 2008 read: 282


PHP String Tips: This post about counting words in a paragraphs or sentences. For this job, we use regular expression pattern to identify individual word in string. Create array content that individual words. Then count that array.


$str = "This site is the Best Step by Step PHP Tutorial.";
$words = preg_split('/[^0-9A-Za-z]+/', $str, -1, PREG_SPLIT_NO_EMPTY);

echo count($words);



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting