\"Lorem Ipsum is simply dummy text of the printing and typesetting industry.\"
from
\"Lorem Ipsum is simply dummy text of the printing and typesetting indust
You can split it using the explode() function.
$sentences = explode (".", $text);
// first sentence is in $sentences[0]
You could use explode() to get the first sentence. http://de.php.net/manual/en/function.explode.php
For PHP 5.3 and later you could use the before_needle argument with strstr:
strstr( $youstringhere, ".", true );
// fastest way
echo substr($text, 0, strpos('.', $text));
What about something like this (others have suggested using explode
-- so I'm suggesting another solution) :
$str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
if (preg_match('/^([^\.]*)/', $str, $matches)) {
echo $matches[1] . '.';
}
The regex will :
^
[^\.]
[^\.]*
And, as you wanted a .
at the end of the output and that .
is not matched by the regex, you'll have to add it back when using what's been found by the regex.