Solved

php script to get first x words of string

Posted on 2013-11-26
2
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

705 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