multiple string separator for explode

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
icesha
Forum Newbie
Posts: 11
Joined: Tue May 01, 2007 3:15 am

multiple string separator for explode

Post by icesha »

hello, i need some help regarding explode function. I want to use a multiple string separator for my explode function. Im exploding sentences with different punctuation marks like "!" or "?" or ","
what i have done is just for sentences that ends with a period.

but when i used separate explode syntx it will just output everything.
please help me. thank you.

Here is an example:

Code: Select all

//this is a code
<?
$var= $_POST['textfield'];
$mypar=explode('.',$var);
//sentence
foreach($mypar as $b)
{
echo "$b - This is a sentence - Ends with a period";
echo "<br/>";
echo "<br/>";
}

?>
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

look into preg_split();
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You should also look into separating on a period and a space, instead of a period. Thinks like Mr., Dr. Ave., $19.99, ... (elipses), etc, all have valid usage of periods within a sentence.
Post Reply