PHPackages                             farzai/thai-slug - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. farzai/thai-slug

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

farzai/thai-slug
================

The Thai text to URL-safe slug converter with multiple transliteration strategies

1.0.0(9mo ago)0124[1 PRs](https://github.com/parsilver/thai-slug-php/pulls)MITPHPPHP ^8.4CI passing

Since Sep 6Pushed 2mo agoCompare

[ Source](https://github.com/parsilver/thai-slug-php)[ Packagist](https://packagist.org/packages/farzai/thai-slug)[ Docs](https://github.com/parsilver/thai-slug-php)[ GitHub Sponsors](https://github.com/parsilver)[ RSS](/packages/farzai-thai-slug/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (9)Versions (4)Used By (0)

Thai Slug PHP
=============

[](#thai-slug-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d3209b1a08a62705480ff0b4e3c135d93166d80eea1ebad8d962f5141cc9e30c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6661727a61692f746861692d736c75672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/farzai/thai-slug)[![Tests](https://camo.githubusercontent.com/cfdedc9552bf1a2a35d10c6d1727f6bddab21749d4c483bd1a66c0b7c686383a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70617273696c7665722f746861692d736c75672d7068702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/parsilver/thai-slug-php/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/a8fca3f0e51ae98079c327fba7e66db83bf786e80274d65d6b0269ad1f93f58d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6661727a61692f746861692d736c75672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/farzai/thai-slug)[![PHP Version Require](https://camo.githubusercontent.com/cf1c2ac5e2ab18680ebf95d8d2e106c4fb0f95366d3306c5977a5c95d409141b/687474703a2f2f706f7365722e707567782e6f72672f6661727a61692f746861692d736c75672f726571756972652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/farzai/thai-slug)

A modern, high-performance PHP library for generating URL-friendly slugs from Thai text with multiple transliteration strategies.

🚀 Features
----------

[](#-features)

- **Multiple Transliteration Strategies**: Phonetic, Royal Thai (RTGS), and Custom rule-based
- **High Performance**: Optimized for fast processing of Thai text
- **UTF-8 Safe**: Proper Thai Unicode normalization and character handling
- **Framework Agnostic**: Works with any PHP framework or standalone

📋 Requirements
--------------

[](#-requirements)

- PHP 8.4 or higher
- mbstring extension (required)
- intl extension (required)
- iconv extension (required)

📦 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require farzai/thai-slug
```

🔥 Quick Start
-------------

[](#-quick-start)

### Basic Usage

[](#basic-usage)

```
use Farzai\ThaiSlug\ThaiSlug;

// Simple slug generation
$slug = ThaiSlug::make('สวัสดีชาวโลก');
// Output: "sawasdee-chao-lok"

$slug = ThaiSlug::make('ภาษาไทยสำหรับการพัฒนา');
// Output: "phasa-thai-samrap-kan-phattana"
```

### Advanced Configuration

[](#advanced-configuration)

```
use Farzai\ThaiSlug\ThaiSlug;
use Farzai\ThaiSlug\Enums\Strategy;

$thaiSlug = new ThaiSlug();

// Using the fluent builder interface
$slug = $thaiSlug->builder()
    ->text('เทคโนโลยีและนวัตกรรม')
    ->strategy(Strategy::ROYAL)    // Use Royal Thai transliteration (RTGS)
    ->maxLength(50)                // Limit slug length
    ->separator('_')               // Use underscore separator
    ->build();

// Output: "theknoloyi_lae_nawatkam"
```

💡 Transliteration Strategies
----------------------------

[](#-transliteration-strategies)

### 1. Phonetic Strategy (Default)

[](#1-phonetic-strategy-default)

Converts Thai text to phonetically similar Latin characters:

```
use Farzai\ThaiSlug\Enums\Strategy;

$slug = ThaiSlug::make('กรุงเทพมหานคร');
// Output: "krung-thep-maha-nakhon"

$thaiSlug->builder()
    ->text('โปรแกรมเมอร์')
    ->strategy(Strategy::PHONETIC)
    ->build();
// Output: "program-mer"
```

### 2. Royal Thai Strategy (RTGS)

[](#2-royal-thai-strategy-rtgs)

Follows the Royal Thai General System of Transcription (official standard):

```
$thaiSlug->builder()
    ->text('สถาบันเทคโนโลยี')
    ->strategy(Strategy::ROYAL)
    ->build();
// Output: "sathaban-theknoloyi"
```

### 3. Custom Strategy

[](#3-custom-strategy)

Define your own transliteration rules:

```
use Farzai\ThaiSlug\Enums\Strategy;

$thaiSlug->builder()
    ->text('ไอทีและเทคโนโลยี')
    ->strategy(Strategy::CUSTOM)
    ->strategyOptions([
        'rules' => [
            'ไอที' => 'IT',
            'เทค' => 'tech',
        ]
    ])
    ->build();
// Output: "IT-lae-tech-noloyi"
```

⚡ Performance
-------------

[](#-performance)

The library is optimized for high performance with Thai text processing:

- **Fast Processing**: Optimized algorithms for Thai text transliteration
- **Memory Efficient**: Minimal memory footprint for typical use cases
- **Modern PHP**: Built with PHP 8.4+ features for optimal performance

### Performance Characteristics

[](#performance-characteristics)

Text SizeTypical Processing TimeMemory UsageSmall (&lt;100 chars)&lt; 1ms&lt; 1MBMedium (100-1K chars)&lt; 5ms&lt; 2MBLarge (1K+ chars)&lt; 50ms&lt; 5MB🔧 Configuration Options
-----------------------

[](#-configuration-options)

### Slug Builder Options

[](#slug-builder-options)

The fluent builder interface provides the following configuration options:

```
use Farzai\ThaiSlug\Enums\Strategy;

$slug = $thaiSlug->builder()
    ->text('ข้อความภาษาไทย')           // Text to convert
    ->strategy(Strategy::PHONETIC)      // Transliteration strategy
    ->maxLength(100)                    // Maximum slug length
    ->separator('-')                    // Separator character
    ->lowercase(true)                   // Convert to lowercase
    ->removeDuplicates(true)            // Remove duplicate separators
    ->trimSeparators(true)              // Remove leading/trailing separators
    ->strategyOptions([])               // Additional strategy-specific options
    ->build();
```

### Available Strategies

[](#available-strategies)

- `Strategy::PHONETIC` - Default phonetic transliteration
- `Strategy::ROYAL` - Royal Thai General System (RTGS)
- `Strategy::CUSTOM` - Custom transliteration rules

🧪 Testing
---------

[](#-testing)

Run the test suite and code quality tools:

```
# Run all tests
composer test

# Run tests with coverage
composer test-coverage

# Run tests with HTML coverage report
composer test-coverage-html

# Code analysis with PHPStan
composer analyse

# Format code with Laravel Pint
composer format

# Check code formatting
composer format-check

# Run all quality checks
composer check-code

# Complete CI pipeline
composer ci
```

📊 Real-World Examples
---------------------

[](#-real-world-examples)

### Blog Post Slugs

[](#blog-post-slugs)

```
$titles = [
    'วิธีการเขียนโค้ด PHP ที่มีประสิทธิภาพ',
    'เทคนิคการออกแบบฐานข้อมูลที่ดี',
    'การใช้ Laravel สำหรับโปรเจคใหญ่',
];

foreach ($titles as $title) {
    $slug = ThaiSlug::make($title);
    echo "Title: $title\n";
    echo "Slug: $slug\n\n";
}

// Output:
// Title: วิธีการเขียนโค้ด PHP ที่มีประสิทธิภาพ
// Slug: withee-kan-khian-kho-php-thee-mee-prasitthiphap

// Title: เทคนิคการออกแบบฐานข้อมูลที่ดี
// Slug: theknit-kan-ok-baep-than-kho-mul-thee-dee

// Title: การใช้ Laravel สำหรับโปรเจคใหญ่
// Slug: kan-chai-laravel-samrap-project-yai
```

### E-commerce Product Names

[](#e-commerce-product-names)

```
$products = [
    'เสื้อยืดผู้ชาย สีน้ำเงิน ไซส์ L',
    'กระเป๋าหนังแท้ สำหรับผู้หญิง',
    'รองเท้าผ้าใบ Nike Air Max',
];

$thaiSlug = new ThaiSlug();

foreach ($products as $product) {
    $slug = $thaiSlug->builder()
        ->text($product)
        ->maxLength(60)
        ->build();

    echo "Product: $product\n";
    echo "Slug: $slug\n\n";
}
```

### URL Generation in Frameworks

[](#url-generation-in-frameworks)

#### Laravel Integration

[](#laravel-integration)

```
// In a Laravel controller
use Farzai\ThaiSlug\ThaiSlug;

class ArticleController extends Controller
{
    public function store(Request $request)
    {
        $slug = ThaiSlug::make($request->input('title'));

        Article::create([
            'title' => $request->input('title'),
            'slug' => $slug,
            'content' => $request->input('content'),
        ]);

        return redirect()->route('articles.show', ['slug' => $slug]);
    }
}
```

#### WordPress Plugin Usage

[](#wordpress-plugin-usage)

```
// WordPress hook
add_filter('wp_unique_post_slug', function ($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug) {
    if ($post_type === 'post' && preg_match('/[\u{0E00}-\u{0E7F}]/u', $original_slug)) {
        return \Farzai\ThaiSlug\ThaiSlug::make($original_slug);
    }
    return $slug;
}, 10, 6);
```

🛡️ Security &amp; Best Practices
--------------------------------

[](#️-security--best-practices)

### Input Validation

[](#input-validation)

```
use Farzai\ThaiSlug\Exceptions\InvalidArgumentException;

try {
    // The library automatically validates and sanitizes input
    $slug = ThaiSlug::make($userInput);
} catch (InvalidArgumentException $e) {
    // Handle invalid input gracefully
    $slug = 'default-slug';
}
```

### Production Best Practices

[](#production-best-practices)

```
use Farzai\ThaiSlug\ThaiSlug;
use Farzai\ThaiSlug\Enums\Strategy;

// Production setup with consistent configuration
$thaiSlug = new ThaiSlug(Strategy::PHONETIC);

// Process user content with validation
$slug = $thaiSlug->builder()
    ->text($userContent)
    ->maxLength(100)
    ->separator('-')
    ->lowercase(true)
    ->build();
```

🔄 Migration Guide
-----------------

[](#-migration-guide)

### From Other Libraries

[](#from-other-libraries)

If you're migrating from other Thai slug libraries:

```
// Old library
$slug = some_old_thai_slug_function('ข้อความไทย');

// New library
$slug = \Farzai\ThaiSlug\ThaiSlug::make('ข้อความไทย');
```

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Please follow these guidelines:

### Development Setup

[](#development-setup)

```
# Clone the repository
git clone https://github.com/parsilver/thai-slug-php.git

# Install dependencies
composer install

# Run tests
composer test

# Run code analysis
composer analyse

# Format code
composer format
```

📝 Changelog
-----------

[](#-changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for more information on what has changed recently.

🔒 Security
----------

[](#-security)

If you discover any security-related issues, please email  instead of using the issue tracker.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

🎯 Performance Tips
------------------

[](#-performance-tips)

1. **Choose appropriate strategy** based on your needs:
    - **Phonetic**: Best for readability and general use
    - **Royal**: Best for official/academic use (RTGS compliant)
    - **Custom**: Best for specialized terminology or domain-specific rules
2. **Set reasonable length limits** using `maxLength()` to prevent overly long slugs
3. **Batch operations** when processing multiple texts to reduce overhead
4. **Use consistent configuration** across your application for predictable results

🙏 Credits
---------

[](#-credits)

- [parsilver](https://github.com/parsilver) - Creator and maintainer
- [All Contributors](../../contributors) - Community contributors

Built with ❤️ for the Thai developer community.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance74

Regular maintenance activity

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

291d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4928451?v=4)[parsilver](/maintainers/parsilver)[@parsilver](https://github.com/parsilver)

---

Top Contributors

[![parsilver](https://avatars.githubusercontent.com/u/4928451?v=4)](https://github.com/parsilver "parsilver (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

urlphpslugseotransliterationthaiphoneticroyal-institute

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/farzai-thai-slug/health.svg)

```
[![Health](https://phpackages.com/badges/farzai-thai-slug/health.svg)](https://phpackages.com/packages/farzai-thai-slug)
```

###  Alternatives

[jbroadway/urlify

A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

6757.8M75](/packages/jbroadway-urlify)[pid/speakingurl

Generate of so called 'static' or 'Clean URL' or 'Pretty URL' or 'nice-looking URL' or 'Speaking URL' or 'user-friendly URL' or 'SEO-friendly URL' or 'slug' from a string.

1.1k5.3k1](/packages/pid-speakingurl)[voku/urlify

PHP port of URLify.js from the Django project. Transliterates non-ascii characters for use in URLs.

254.2M8](/packages/voku-urlify)[wazum/sluggi

TYPO3 extension for URL slug management with inline editing, auto-sync, locking, access control, and redirects

41515.2k](/packages/wazum-sluggi)[koehlersimon/slug

Helps you managing the URL slugs of your TYPO3 site

2965.7k](/packages/koehlersimon-slug)[jaybizzle/safeurl

A Laravel package to create safe, SEO friendly urls

1788.3k1](/packages/jaybizzle-safeurl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
