Search
 
SCRIPT & CODE EXAMPLE
 

PHP

create slug with php

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 :: php for loop array 
Php :: php token generator 
Php :: convert array to string laravel 
Php :: php setinterval 
Php :: laravel model limit 
Php :: foreach loop 1-100 php 
Php :: php create an image 
Php :: laravel timestamp 
Php :: sum of columns laravel eloquent 
Php :: php counter 
Php :: php remove last newline from string 
Php :: delete all cookies in php 
Php :: php error reporting 
Php :: array reduce associative array php 
Php :: laravel get all users except role spatie 
Php :: php json request get value of an array element 
Php :: remove last all special character from string php 
Php :: phpspreadsheet read xlsx 
Php :: laravel migration index 
Php :: how to zip a folder using php 
Php :: round up built in function php 
Php :: each in laravel 
Php :: wordpress get post body 
Php :: php fix array index 
Php :: date diff php 
Php :: laravel file permissions 
Php :: php return json data 
Php :: twig variable exists 
Php :: validate laravel 
Php :: offset codeigniter 3 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =