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

  • SEARCH
  • Home
  • 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 7575557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:42:49+00:00 2026-05-30T16:42:49+00:00

I am trying to create a function to create permalinks. This is what I

  • 0

I am trying to create a function to create permalinks.
This is what I have until now:

public function createPermalink($permalink)    
{    
  $new_perma = strtolower($permalink);    
  $searchsigns = array('Ö', 'Ä', 'Ü', 'ß', '-', '_', ' ', 'ö', 'ä', 'ü');    
  $replaces = array('oe', 'ae', 'ue', 'ss', '', '-', '-', 'oe', 'ae', 'ue');    
  $new_perma = str_replace($searchsigns, $replaces, $new_perma);    
  $new_perma = preg_replace('/[^a-z0-9_-]/isU', '', $new_perma);    
  return $new_perma;    
}

Now imagine the variable $permalink would be say 5 free spaces (doesn’t make sense, but a user could possibly enter it). Now what would happen is that the $new_perma would be -----
So there is the problem, in the URL there is only one - allowed. Obviously I could at the end use str_replace to replace 2, 3, 4, 5 … dashes behind each other. But I would need to specify the search pattern for any possible amount of dashes. So what I need is a way to remove all dashes inside the variable $new_parma, which are more than one in a row.

  • 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-05-30T16:42:49+00:00Added an answer on May 30, 2026 at 4:42 pm

    Add this just before the return of your function:

    $new_perma = preg_replace('/-+/', '-', $new_perma);
    

    The + means ‘one or more’. So this pattern replaces one or more dashes with a single dash.

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

Sidebar

Related Questions

I'm trying to create a function which takes an array as an argument, adds
I'm trying to create a function that would dynamically allocate an array, sets the
I am trying to create a function with options. I believe I have to
I'm trying create this function such that if any key besides any of the
I'm trying to create this function: CREATE FUNCTION remove_non_alphanum (prm_strInput varchar(3000)) RETURNS VARCHAR(3000) DETERMINISTIC
I'm trying to create function that will do this same thing for 3 different
I'm trying to create a function that will loop through an array of various
I'm trying to create a function in C# which will allow me to, when
I'm trying to create a function that searches up a WebControl's parent-child relationship (basically
I am trying to create a function which will give me alphabet position when

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.