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 8684719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:22:34+00:00 2026-06-12T22:22:34+00:00

On my website, I let the user send tags like this: tag tagtwo anothertag

  • 0

On my website, I let the user send tags like this:

tag tagtwo anothertag

I only want to allow them to use single spaces and letters, so I want to remove numbers, dashes, double spaces, etc. So an invalid string would be:

tag       tag2 another-tag

I have the following code to do this, but I don’t know the correct regex to use.

$tags = strtolower($_POST['imgTags']);
$tags = preg_replace("/regex/", "", $tags);
$tagArray = explode(" ", $tags);

What is the correct regEx to do this?
Also, I might want to replace é and ö with e and o.

  • 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-12T22:22:36+00:00Added an answer on June 12, 2026 at 10:22 pm

    This will remove anything but letters and spaces:

    $tags = preg_replace("/[^a-z ]/i", "", $tags);
    

    Then this will collapse consecutive spaces:

    $tags = preg_replace("/ {2,}/", " ", $tags);
    

    If you want to allow other kinds of whitespace characters, but also replace them with single spaces, try this instead:

    $tags = preg_replace("/[^a-z\s]/i", "", $tags);
    $tags = preg_replace("/\s+/", " ", $tags);
    

    Regarding your last sentence: there is no generic way to this. You will have to add specific rules. However, preg_replace_callback might help you in determining the unmodified letters.

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

Sidebar

Related Questions

Let's say i allow the user to upload a file to my website. Using
After user registration, website send activation code to email. something like that. www.domain.com/?activate=<code> I'm
I want to make a page for a website that will let the user
My goal I would like to let browsers cache my whole website, but only
I'm building a website with Rails which can let user check if some domains
In my website, I want to let the admins reset the password of any
Let's suppose that you have a website that contains a single button. When this
Let's imagine that we have ecommerce website that suggests 3 way for user registration:
Let say I have a website that allows users to send articles on that
Is it ok to let user of a website customise and store theire own

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.