79367441

Date: 2025-01-18 15:55:09
Score: 0.5
Natty:
Report link

I found a way to get three sentences

<?php
$content = "My name is Luka. I live on the second floor. I live upstairs from you. Yes I think you've seen me before. ";
$dot = ".";

$number_of_sentences = substr_count($content, '.');

$first_dot = stripos ($content, $dot, 0);
$second_dot = stripos ($content, $dot, $first_dot+1);
$third_dot = stripos ($content, $dot, $second_dot+1);

if ($first_dot) {
    $first_sentence = substr($content, 0, $first_dot);
}
if ($second_dot) {
    $second_sentence = substr($content, 0, $second_dot);
}
if ($third_dot) {
    $third_sentence = substr($content, 0, $third_dot);
}


if ($number_of_sentences > 0) {
    echo $first_sentence . '.<hr>'; //first sentence
}
if ($number_of_sentences > 1) {
    echo $second_sentence . '<hr>'; //second sentence
}
if ($number_of_sentences > 2) {
   echo $third_sentence . '<hr>'; // third
}

echo $number_of_sentences;

?>

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: SuperMan