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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:54:25+00:00 2026-05-26T00:54:25+00:00

First off, if it’s not clear from the tag, I’m doing this in PHP

  • 0

First off, if it’s not clear from the tag, I’m doing this in PHP – but that probably doesn’t matter much.

I have this code:

$inputStr = strip_tags($inputStr);
$inputStr = preg_replace("/[^a-zA-Z\s]/", " ", $inputStr);

Which seems to remove all HTML tags and virtually all special and non-alphabetic characters perfectly. The one problem is, for some reason, it doesn’t filter out carraige return/line feeds (just the combination).

If I add this line:

$inputStr = preg_replace("/\s+/", " ", $inputStr);

at the end, however, it works great. Can someone tell me:

  1. Why doesn’t the first preg_replace filter out the CR/LFs?
  2. What this second preg_repalce is actually doing? I understand the first one for the most part, but hte second one is confusing me – it works but I don’t know why.
  3. Can I combine them into 1 line somehow?
  • 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-26T00:54:25+00:00Added an answer on May 26, 2026 at 12:54 am

    Your first regex is removing all characters that are not letters or whitespace. CRLFs are whitespace, so they aren’t filtered out.

    The second one is replacing whitespace with a space character. Essentially it condenses sequences of whitespace into a single space (due to the quantifier being greedy).

    I suggest removing the \s from the first regex, see if that works.

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

Sidebar

Related Questions

First off, it may seem that I'm asking for subjective opinions, but that's not
First off, I am cross-posting this from Server Fault because I did not receive
First off, I'm not all that familiar with cookies but I know how they
First off, let me start off that I am not a .net developer. The
First off, this question is ripped out from this question. I did it because
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS
First off, I know that this question begs the other question - should the
first off this is a class assignment so i would appreciate help but just
First off: Everything works , but I would like to fine tune this a
First off, I would like to say that I am just starting with PHP

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.