Search
 
SCRIPT & CODE EXAMPLE
 

PHP

string to slug php

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;
}

echo slugify('Hello World'); //hello-world
echo slugify('Hello World', '_'); //hello_world
Comment

convert text to slug php

public static function createSlug($str, $delimiter = '-'){

    $slug = strtolower(trim(preg_replace('/[s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter));
    return $slug;

}
Comment

PREVIOUS NEXT
Code Example
Php :: Add 7 days to the current date in PHP 
Php :: php artisan cache:clear Failed to clear cache. Make sure you have the appropiate permissions 
Php :: increase upload limit in phpmyadmin docker 
Php :: laravel get url without domain in blade 
Php :: PHP strrev — Reverse a string 
Php :: Laravel Validation check array size min and max 
Php :: php get extension from file from form submit 
Php :: inner join codeigniter 
Php :: laravel maintenance mode 
Php :: delete all rows in table laravel 
Php :: non negative integer validation laravel 
Php :: php print array 
Php :: php prime numbers 
Php :: Add 5 days to the current date in PHP 
Php :: default php program 
Php :: how to create shortcode 
Php :: how to pass variable in inside function into where in laravel 
Php :: php object(stdclass) to array 
Php :: array_key_exists vs isset 
Php :: php pdo select 
Php :: how to search two needle in an array in_array php 
Php :: php check if date is older than 1 month 
Php :: laravel 8 date difference in days 
Php :: where_in codeigniter 
Php :: sustituir caracteres especiales php 
Php :: php artisan vendor:publish 
Php :: php unset array key 
Php :: laravel check if request wantsjson 
Php :: cookie are not set in php 
Php :: query builder "not in" laravel 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =