String to Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jwerre
Forum Newbie
Posts: 18
Joined: Thu Feb 05, 2009 5:06 pm

String to Array

Post by jwerre »

Is there a simple way to convert a paragraph of text into an array of sentences?

How would I turn this:
$paragraph = "Sentence number one. Sentence number two. Sentence number three."

...into this:
Array([0]=>"Sentence number one." [1]=>"Sentence number two."[3]=>"Sentence number three.")

Isn't there a split method or something in php?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: String to Array

Post by requinix »

It can get really complicated really quickly.

If you don't have words like "Mr." or numbers like "1.2" then you can explode on a period. Otherwise you're probably stuck with regular expressions.
(PS: We have a Regex forum.)
Post Reply