I'm trying to find the break up a string to show only the first sentence...
I have an item description stored as $string, and I want an abreviated description, showing only the first sentence (which will then be abbreviated to x characters + ... later)
The problem is, I've been going around in circles trying to find the right way to break up the description.
the best I've come up with is to use
strpos();
to find the positions of the various sentence-breaking punctiations ('.','!','?',':',';') - but I can't find a [short] way to find which is the first occuring one...
my code so far:
function shortdesc($item) {
$period=strpos($item, ".");
if ($period===false) {
$period=10000;
}
$exclam=strpos($item, "!");
if ($exclam===false) {
$exlam=10000;
}
$question=strpos($item, "?");
if ($question===false) {
$question=10000;
}
$semicol=strpos($item, ";");
if ($semicol===false) {
$semicol=10000;
}
$colon=strpos($item, ":");
if ($colon===false) {
$colon=10000;
}
// find some way to find the string with smallest value to then execute an explode() command
}
Any thoughts?