[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php script to get first x words of string

Posted on 2013-11-26
2
Medium Priority
?
273 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 85

Accepted Solution

by:
ozo earned 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month19 days, 4 hours left to enroll

834 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