Jump to content

How can I extract sentences from a block of text?


phpkeithphp

Recommended Posts

Scenario:

 

I have a form textarea containing a main heading, 1 or more paragraphs, and 1 or more subheadings.

 

I would like to extract the sentences/headings and put them into an array using the following rules:

 

- headings will not have punctuation necessarily so to differentiate them they will have a blank line beneath them, but I don't want them to be confused with the last sentence in a parapgraph. When re-displaying the text block I want to re-display it as a heading (with a blank line above and below it for subheadings and a blank line below for the main heading)

- I do not want to simply look for "." to determine the end of a sentence because it may be a domain name or currency. Perhaps consider the end of a sentence to have punctuation plus 1 character of white space?

- Also if multiple sentences are wrapped in quotes; for example "Sentence 1. Sentence 2? Sentence3!" I would like to treat that as 1 sentence.

 

I don't even know where to begin.

 

Thanks in advance!

Link to comment
Share on other sites

Begin with exactly what you listed. It seems like you know what you want specifically. Now all you need to do is translate that into a few lines of code. Since you already know what characters are allowed in the heading and paragraphs, this shouldn't be too hard.

 

Look into preg_match and some Regular Expressions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.