PHP Slug Generator Function Class: Generate a slug text to use in a URL from a string

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-11-19 (9 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 29 This week: 6All time: 10,042 This week: 31Up
Version License PHP version Categories
slug 1.0The PHP License5PHP 5, Text processing
Description Author

This is a simple class that can generate a slug text to use in a URL from a string.

It can text string as parameter to lower the case of capital letters and replaces space characters by dashes.

The class returns the resulting string, it it can be used as part a Web site page URL to make it more readable to humans.

Picture of Channaveer Hakari
  Performance   Level  
Name: Channaveer Hakari <contact>
Classes: 3 packages by
Country: India India
Age: 30
All time rank: 3017199 in India India
Week rank: 27 Up5 in India India Up

 

Details

About Simple Slug Generator

Hi with the help of this page you can generate simple Slug

Working Basic Example To Generate Slug

<?php
require_once './vendor/autoload.php';

use Channaveer\Slug\Slug;

$string = "How To Create A Composer Package? Test It Locally And Add To Packagist Repository";

echo Slug::create($string);

Generate UNIQUE Slugs Example

<?php
require_once './vendor/autoload.php';

use Channaveer\Slug\Slug;

$title  = "How To Create A Composer Package? Test It Locally And Add To Packagist Repository";

$slug   = Slug::create($title);

/ Following is the simple PDO Query to check the 
 total number of blog with similar slug name/
$blog_count_stmt = $pdo->prepare("
                    SELECT
                        COUNT(`id`) slug_count
                    FROM
                        `articles`
                    WHERE
                        `slug` LIKE :slug
                ");

$blog_count_stmt->execute([
    ":slug" => "%".$slug."%"
]);

$blog_count = $blog_count_stmt->fetchObject();

if ($blog_count && $blog_count->slug_count > 0) {
    $article_increment = $blog_count->slug_count + 1;
    $slug = $slug . '-' . $article_increment;
}

echo 'Your unique slug - <br/>'. $slug;
  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  src  
File Role Description
  Plain text file Slug.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:29
This week:6
All time:10,042
This week:31Up

For more information send a message to info at phpclasses dot org.