• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 857
  • Last Modified:

PHP Word count and sentence break

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
jbrashear72
Asked:
jbrashear72
1 Solution
 
JB04Commented:
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
 
Strychni9eCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now