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 :: wp limit post revisions 
Php :: get author display name wordpress 
Php :: laravel between dates 
Php :: codeigniter db where between 
Php :: php get id from url 
Php :: php convert array to object 
Php :: php check if input is date 
Php :: composer create project laravel 7 
Php :: php get ip address of visitor 
Php :: php remove everything after character 
Php :: convert base64 string to pdf in php 
Php :: date_default_timezone_set for india in php 
Php :: How to prevent Browser cache for php site 
Php :: wp_get_attachment_image class 
Php :: jdate get one day before php 
Php :: wordpress disable errors 
Php :: javascript php variable 
Php :: db symfony 
Php :: Find ip address location php 
Php :: No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration 
Php :: PHPspreadsheet getColumnDimension 
Php :: laravel collection filter 
Php :: php print top n of array 
Php :: [InvalidArgumentException] Could not find package laravel/laravel with version 7.0 in a version installable using your PHP version, PHP extensions and Composer version. 
Php :: In php, how to convert string value into an int 
Php :: yii2 htpp client form data 
Php :: laravel json response decode 
Php :: php date from mysql and date 
Php :: add to url anchor tag laravel with variable 
Php :: php url parse 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =