Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php slugify

public static function slugify($text, string $divider = '-')
{
  // replace non letter or digits by divider
  $text = preg_replace('~[^pLd]+~u', $divider, $text);

  // transliterate
  $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

  // remove unwanted characters
  $text = preg_replace('~[^-w]+~', '', $text);

  // trim
  $text = trim($text, $divider);

  // remove duplicate divider
  $text = preg_replace('~-+~', $divider, $text);

  // lowercase
  $text = strtolower($text);

  if (empty($text)) {
    return 'n-a';
  }

  return $text;
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel websockets onmessage 
Php :: how to show validation error in laravel 8 
Php :: composer update withou memory limit 
Php :: wordpress notice 
Php :: laravel @canany 
Php :: how to redirect to another page from laravel blade 
Php :: laravel api enable cors 
Php :: laravel order by relationship 
Php :: php number to color 
Php :: serve in localhost using php 
Php :: php read csv file into array 
Php :: php month single digit 
Php :: php change array into comma delimited string 
Php :: format money with commas in php 
Php :: php foreach count rows 
Php :: array_key_exists vs in_array 
Php :: php curl example 
Php :: php sql get single value 
Php :: pass parameter to view laravel 
Php :: php token generator 
Php :: laravel blade get array count in Blade 
Php :: wordpress add to cart redirect php 
Php :: php remove last newline from string 
Php :: composer create project laravel 
Php :: laravel model created_at format edit 
Php :: Flutter migrate to Android Studio 
Php :: get slogan wp 
Php :: connect to sql database 
Php :: eloquent get only some columns 
Php :: each in laravel 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =