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

x
?
Solved

PHP Word count and sentence  break

Posted on 2006-03-30
2
Medium Priority
?
838 Views
Last Modified: 2013-12-12
I have a form that I want to submit a Large set of text into.

I want to break it into paragraphs.

So I want to count in 3 -5 Sentences  add a line break and put in a word like BREAK or #BREAK# in between each set then echo it back to the screen.

How would this be done?
A sentence ends with a      .    or a ! or a ?
Also how can I show a total word count of the input text?

Here is the form that I have that submits the data.

<html>
<head>
<title>paragraph burst</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="<? $phpself; ?>">
  <p> Insert Text<br>
    <textarea name="original_text" cols="150"></textarea>
  </p>
  <p>min Sentence
    <input name="min" type="text" value="3" size="4">
    Max sentence
    <input name="max" type="text" value="5" size="4">
    <br>
    Break Token
    <input name="break_name" type="text" value="#BREAK#">
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>
</body>
</html>


I hope that this is easy..
0
Comment
Question by:jbrashear72
2 Comments
 
LVL 7

Accepted Solution

by:
JB04 earned 2000 total points
ID: 16341632
I dont full understand your question, however to wrap a line of text use wordwrap


$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");

echo $newtext;



www.php.net/wordwrap



to count the characters use the strlen function


$test = 'hello';

echo strlen($test); - outputs 5
0
 
LVL 2

Expert Comment

by:Strychni9e
ID: 16347616
you can use <a href="http://us2.php.net/manual/en/function.preg-split.php">preg_split()</a>

and a perl regexp to split it into arrays of sentances something like preg_split("[.!?]",$mytext)

then output then from the array as use feel the need

foreach( $array as $key => $value){}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to count occurrences of each item in an array.
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.
Suggested Courses

872 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