title: PHP sentence case function
body: <p>I have got a function from Google to clean my paragraph in sentence case.</p>
  
  <ol>
  <li><p>I want to modify this function such that it converts more than 2 new line character to newline. Else it converts all new line characters in space. So I would have it in paragraph format. Here it's converting all new line character to space.</p></li>
  <li><p>It's converting in proper sentence case. But, In case If I found single word having first word as capital then I need function to ignore that. As Sometimes, if there would be any noun It needs to be capital. We can't change it small case. Else if noun and it is having more than 2 capital characters other than first character than convert it to lower case.</p></li>
  </ol>
  
  <p>Like -> <code>Noun =&gt; Noun</code> but <code>NoUn =&gt; noun</code>. Means I want if other than first character is capital than it convert it two lower case Else it keep it in same format.</p>
  
  <pre><code>function sentence_case($string) {
  $sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
  $new_string = '';
  foreach ($sentences as $key =&gt; $sentence) {
      $new_string .= ($key &amp; 1) == 0?
          ucfirst(strtolower(trim($sentence))) :
          $sentence.' ';
  }
  $new_string = preg_replace("/\bi\b/", "I", $new_string);
  //$new_string = preg_replace("/\bi\'\b/", "I'", $new_string);
  $new_string = clean_spaces($new_string);
  $new_string = m_r_e_s($new_string);
  return trim($new_string);
  }
  </code></pre>