“ślimak w php” Kod odpowiedzi

String to Slug PHP

function slugify($text, string $divider = '-')
{
  // replace non letter or digits by divider
  $text = preg_replace('~[^\pL\d]+~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
Beautiful Bug

PHP zdobądź ślimak

You can get that using the following methods:

<?php $post_slug = get_post_field( 'post_name', get_post() ); ?>
Or You can use this easy code:

<?php
    global $post;
    $post_slug = $post->post_name;
?>
Santino

Utwórz ślimak z PHP

public static function slugify($text, string $divider = '-')
{
  // replace non letter or digits by divider
  $text = preg_replace('~[^\pL\d]+~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;
}
Meti

ślimak w php

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

Odpowiedzi podobne do “ślimak w php”

Pytania podobne do “ślimak w php”

Więcej pokrewnych odpowiedzi na “ślimak w php” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu