Download the PHP package techecosystem/parsify-php without Composer
On this page you can find all versions of the php package techecosystem/parsify-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download techecosystem/parsify-php
More information about techecosystem/parsify-php
Files in techecosystem/parsify-php
Package parsify-php
Short Description A PHP library for Persian text conversion, including number translation, diacritics removal, and normalization with a fluent API.
License MIT
Homepage https://github.com/techecosystem/parsify-php
Informations about the package parsify-php
Persian Converter Library
The Persian Converter Library is a powerful tool designed to handle Persian text conversion, including removing diacritics, converting numbers between English and Persian, and other text normalizations. This library provides an easy-to-use interface for developers to work with Persian text more effectively.
Features
- Convert English numbers to Persian and vice versa.
- Remove diacritics from Persian text.
- Highly customizable through a fluent builder pattern.
- Lightweight and efficient.
Installation
To install the library, you can use Composer:
API Documentation
PersianConverterBuilder Class
The PersianConverterBuilder
class provides a fluent interface to create a PersianConverter
with customizable strategies for text normalization and number conversion.
Methods
-
static create(): self
-
Creates and returns a new instance of the builder.
- Example:
-
-
withNumberConversion(bool $keepEnglishNumbers = false): self
-
Enables number conversion. By default, converts English and Arabic numbers to Persian numbers.
-
Parameters:
-
bool $keepEnglishNumbers
(default:false
): Whether to keep English numbers. -
If
$keepEnglishNumbers
istrue
, only Arabic numbers are converted. - Example:
-
-
withTextNormalization(bool $keepPersianDiacritic = true): self
-
Enables text normalization. Optionally keeps Persian diacritics.
-
Parameters:
-
bool $keepPersianDiacritic
(default:true
): Whether to keep Persian diacritics. - Example:
-
-
build(): PersianConverter
-
Builds and returns a
PersianConverter
instance with the configured strategies. -
Throws:
-
MissingStrategyException
If no strategies are enabled, i.e., both text normalization and number conversion are disabled. - Example:
-
PersianConverter Class
The PersianConverter
class applies various conversion strategies to normalize Persian text and convert numbers.
Methods
-
static createDefault(): self
-
Creates a default
PersianConverter
with text normalization and Persian number conversion enabled. - Example:
-
-
convert(string $input): string
-
Applies all strategies to the input string and returns the converted text.
-
Throws:
-
TextConversionException
on conversion failure. - Example:
-
PersianTextService Class
The PersianTextService
class provides utility methods for text normalization using PersianConverter
with various configurations.
Methods
-
static normalize(string $input): string
Normalizes the text with default settings (text normalization and Persian number conversion).- Example:
-
static normalizeTextWithEnglishNumbers(string $input): string
-
Normalizes the text while keeping English numbers.
- Example:
-
-
static normalizeTextWithoutNumbers(string $input): string
-
Normalizes the text without converting numbers.
- Example:
-
Examples
-
Simple Text Normalization
-
Normalization with English Numbers
-
Normalization without Number Conversion
-
Custom Converter: Combining Multiple Conversions
The library allows chaining multiple conversion rules in one go:
-
Removing Diacritics
You can also remove diacritics from Persian text using the following approach:
Contributing
Please see CONTRIBUTING for details.
License
This library is open-source software licensed under the MIT license.