Search
 
SCRIPT & CODE EXAMPLE
 

PHP

slug in php

$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
Comment

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 :: how to display user id from a function on a wordpress page 
Php :: get url with php 
Php :: wp create user programmatically 
Php :: time in php 
Php :: laravel redirect back url with message 
Php :: make model inside module laravel 
Php :: gmdate in php 
Php :: upgrade php linux 
Php :: laravel 8 insert multiple rows 
Php :: web scraping php 
Php :: How to validate a file type in laravel 
Php :: set session after login with laravel 
Php :: migration create symfony 
Php :: remove foreign key constraint laravel 
Php :: php isset multiple 
Php :: json_decode object to array 
Php :: PHP (WordPress) - Increase Maximum Upload File Size 
Php :: register_post_type wordpress 
Php :: laravel model with methos custom columns 
Php :: acf repeater 
Php :: array_push in php 
Php :: larvel make http request 
Php :: php sort associative array by specific value 
Php :: laravel access JsonResponse content 
Php :: search post by post title in wordpres 
Php :: use php variable in html attributes 
Php :: add two numbers as string in php 
Php :: random string generator php 
Php :: create listener using laravel 
Php :: search function using php for database entries 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =