看不懂第一个字母

I want to add a function to return whether the first letter is a capital or not from my last question.

Here's the code:

<?php

function isCapital($string) {
   return $string = preg_match('/[A-Z]$/',$string{0});
}

$text = " Poetry. do you read poetry while flying? Many people find it relaxing to read on long flights. Poetry can be divided into several genres, or categories. ";
$sentences = explode(".", $text); $save = array();
foreach ($sentences as $sentence) {
   if (count(preg_split('/\s+/', $sentence)) > 6) {
      $save[] = $sentence. ".";
   }
}

if( count( $save) > 0) {
   foreach ($save as $nama){
      if (isCapital($nama)){
         print_r ($nama);
      }
   }
}
?>

The result should be...

Poetry can be divided into several genres, or categories.

...but it prints nothing. I need only the sentence that consists of more than 6 words and start with capital letter.

When you do the explode() function, you are leaving a space at the start of the string, which means that the leftmost character of $string will never be a capital letter--it will be a space. I would change the isCapital() function to the following:

function isCapital($string) {
  return preg_match('/^\\s*[A-Z]/', $string) > 0;
}

You should be able to accomplish all of this through one regular expression, if you're so inclined:

preg_match_all('/((?=[A-Z])([^\s.!?]+\s+){5,}[^\s.!?]+[.!?])/', $string, $matches);

http://refiddle.com/2hz

Alternatively, remove the ! and ? from the character classes to only count . as a sentence delimiter.