phpkeithphp Posted May 16, 2009 Share Posted May 16, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/158403-how-can-i-extract-sentences-from-a-block-of-text/ Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/158403-how-can-i-extract-sentences-from-a-block-of-text/#findComment-835413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.