Download the PHP package tinusg/syllable-counter without Composer

On this page you can find all versions of the php package tinusg/syllable-counter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package syllable-counter

Syllable Counter

Counts and hyphenates the syllables of Dutch — and Dutch-spelled international — names and words, without a dictionary, a pattern file or an API call. Pure spelling rules, one small class, no runtime dependencies beyond illuminate/support for the service provider.

Try it in the browser: live demo.

A JavaScript port with the same rules lives in tinusg/syllable-counter-js.

Installation

The service provider is auto-discovered. Publishing the config is optional:

Usage

Resolve it from the container (recommended — it picks up your config) or just new it up:

Method Returns Example
count(string $value, ?bool $muteFinalE = null): int Number of syllables, never less than 1 count('Olivia')4
split(string $value, ?bool $muteFinalE = null): array The syllables, casing and accents intact split('Sophia')['So', 'phi', 'a']
hyphenate(string $value, string $separator = '-', ?bool $muteFinalE = null): string The hyphenated word hyphenate('Olivia')'O-li-vi-a'

count() runs through split(), so counting and hyphenating can never disagree.

Spaces and hyphens are word boundaries; every word contributes its own syllables:

How it works

The whole thing rests on one rule: a syllable has exactly one vowel nucleus. So finding the nuclei and dividing the consonants between them gives you both the count and the hyphenation.

1. Normalise, but remember the accents

The word is lower-cased and diacritics are reduced to their base letter (ée, çc). Positions that carried a diaeresis or an accent are flagged, because those mark a vowel that is pronounced on its own. Without that flag Chloë and Chloé would both read as the digraph oe and come out as one syllable; with it they correctly split into Chlo-ë and Chlo-é.

2. Find the vowel nuclei

Adjacent vowels are collected into runs, and each run is cut into nuclei with a greedy match on known vowel groups:

Two letters get special treatment:

3. Divide the consonants: maximal onset

For the consonant cluster between two nuclei, as much of it as possible moves to the following syllable, as long as the part that moves is a valid Dutch onset (br, chr, kn, zw, th, …). A single consonant is always a valid onset, so V-CV is the default:

4. The final e

Whether a final e is pronounced is not a spelling question — Céline (mute) and Eline (pronounced) share the same -ine ending — so it cannot be derived from the letters. The package handles this in two layers:

null (the default) means "no knowledge, use the heuristic". The flag applies to the last word only, so hyphenate('Marie-Alice', '-', true) gives Ma-rie-A-lice.

5. Exceptions, last

A handful of names break every rule Dutch spelling has — James is one syllable, Ga-bri-el splits where the digraph rule says it should not, Turkish -ce names pronounce their final e. Those live in a small exception list that is checked before the rules run.

An exception stores the syllables in lower case; the original is then cut at those same lengths, so capitals and accents survive: GABRIELGA-BRI-EL. If the exception does not match the length of the input, it is ignored and the normal rules apply.

Add your own in config/syllable-counter.php (an entry overrides a built-in one with the same key):

Or pass them straight to the constructor:

What it does not do

It produces orthographic hyphenation (So-phi-a), not a phonetic transcription, and it is tuned for names. The rules are Dutch, so an English word with an English-only spelling pattern can come out wrong. It is a rule set, not an oracle — when you need a specific word to be exact, add an exception.

Testing

The suite is a large table of real names — Dutch, Turkish, Arabic, French, Latin, English — with their expected counts and hyphenations. If you find a name that comes out wrong, a pull request with that name added to the table is the most useful thing you can send.

Thanks

This package was extracted from the code that powers two Dutch sites, and it exists because they needed it:

If this package is useful to you, a link back to naampedia.nl and puzzelpedia.nl — in your README, your credits page or wherever you list what you build on — would be very much appreciated. That is the whole price.

License

MIT. See LICENSE.


All versions of syllable-counter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-mbstring Version *
illuminate/support Version ^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tinusg/syllable-counter contains the following files

Loading the files please wait ...