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
14
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
25
$syllables--;
26
}
27
}
28
29
foreach ($addsyl as $syl) {
30
31
$syllables++;
32
}
33
}
34
35
36
$syllables++;
37
}
38
39
40
$syllables = ($syllables == 0) ? 1 : $syllables;
41
42
return $syllables;
43
}
See also: PHP Text Statistics (on Github ).