Solved

php script to get first x words of string

Posted on 2013-11-26
2
265 Views
Last Modified: 2013-11-26
$string='This, is a big test. This is not a big test';

$search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript
       '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
       '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
       '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments including CDATA
                        );
$text = preg_replace($search, '', $string);
$words = str_word_count($text, 2);
return array_slice( $words, 0, 7);


result='This is a big test This is';

Issue
this script removes the fullstop and coma

What I want to return is 'This, is a big test. This is'
.... maintain the coma and fullstop

Can you help?
0
Comment
Question by:joomla
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 39679992
$words = str_word_count($text, 2, '.,');
0
 

Author Closing Comment

by:joomla
ID: 39679997
thanks ozo,
i could have saved myself a lot of time by actually reading the manual.
thanks for your help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now