RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

Count The Number Of Syllables in a Word With PHP

This PHP function to count syllables in a word isn't entirely reliable, but we're providing it despite its lack of accuracy. It supports, in part, the article published here (Count Sentences, Words, and Syllables With PHP).

1
<?php 
2
/*
3
 Count the number of syllables in a word
4
 http://www.beliefmedia.com/count-sentences-syllables-php
5
*/
6
 
7
function beliefmedia_count_syllables($word) {
8
 
9
  $subsyl = Array('cial','tia','cius','cious','giu','ion','iou','sia$','.ely$');
10
  $addsyl = Array('ia','riet','dien','iu','io','ii','[aeiouym]bl$','[aeiou]{3}','^mc','ism$','([^aeiouy])\1l$','[^l]lien','^coa[dglx].','[^gq]ua[^auieo]','dnt$');
11
 
12
  /* Based on Greg Fast's Perl module Lingua::EN::Syllables */
13
  $word = preg_replace('/[^a-z]/is', '', strtolower($word));
14
  $word_parts = preg_split('/[^aeiouy]+/', $word);
15
 
16
  foreach ($word_parts as $key => $value) {
17
    if ($value <> '') {
18
      $valid_word_parts[] = $value;
19
    }
20
  }
21
 
22
  $syllables = 0;
23
  foreach ($subsyl as $syl) {
24
    if (strpos($word, $syl) !== false) {
25
      $syllables--;
26
    }
27
  }
28
 
29
  foreach ($addsyl as $syl) {
30
    if (strpos($word, $syl) !== false) {
31
      $syllables++;
32
    }
33
  }
34
 
35
  if (strlen($word) == 1) {
36
    $syllables++;
37
  }
38
 
39
  $syllables += count($valid_word_parts);
40
  $syllables = ($syllables == 0) ? 1 : $syllables;
41
 
42
 return $syllables;
43
}

See also: PHP Text Statistics (on Github ).

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment