Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:02:52+00:00 2026-06-15T10:02:52+00:00

I am trying to create slugs for urls. I have the following test string

  • 0

I am trying to create slugs for urls.

I have the following test string :

$kw='Test-Tes-Te-T-Schönheit-Test';

I want to remove small words less than three characters from this string.

So, I want the output to be

$kw='test-tes-schönheit-test';

I have tried this code :

$kw = strtolower($kw);
$kw = preg_replace("/\b[^-]{1,2}\b/", "-",  $kw);
$kw = preg_replace('/-+/', '-', $kw);
$kw = trim($kw, '-');
echo $kw;

But the result is :

test-tes-sch-nheit-test

so, the German character ö is getting removed from the string
and German word Schönheit is being treated as two words.

Please suggest how to solve this.

Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:02:53+00:00Added an answer on June 15, 2026 at 10:02 am

    I assume, your string is not UTF-8. With Umlauts/NON-ASCII characters and regex I think, its easier first to encode to UTF-8 and then – after applying the regex with u-modifier (unicode) – if you need the original encoding, decode again (according to local). So you would start with:

    $kw = utf8_encode(strtolower($kw));
    

    Now you can use the regex-unicode functionalities. \p{L} is for letters and \p{N} for numbers. If you consider all letters and numbers as word-characters (up to you) your boundary would be the opposite:

    [^\p{L}\p{N}]
    

    You want all word-characters:

    [\p{L}\p{N}]
    

    You want the word, if there is a start ^ or boundary before. You can use a positive lookbehind for that:

    (?<=[^\p{L}\p{N}]|^)
    

    Replace max 2 “word-characters” followed by a boundary or the end:

    [\p{L}\p{N}]{1,2}([^\p{L}\p{N}]|$)
    

    So your regex could look like this:

    '/(?<=[^\p{L}\p{N}]|^)[\p{L}\p{N}]{1,2}([^\p{L}\p{N}]|$)/u'
    

    And decode to your local, if you like:

    echo utf8_decode($kw);
    

    Good luck! Robert

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create slugs. My string is like this: $string='möbel#*-jérôme-mp3-how?'; Step: 1
I have a prob. I'm trying to create a custom slugify functiom. I use
I'm trying to create custom URLs for my site's users: www.mysite.com/user1 If I set
I am trying to create a Content Management System using Codeigniter. I have a
I'm trying to create an admin backend for a cms. So I have a
I'm trying to create model Page, page should be able to have child pages
I want to create a Category class that may or may not have a
I've been trying to make my Rails create URLs to show records by using
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.