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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:50:58+00:00 2026-06-08T02:50:58+00:00

The problem I’m encountering with this is if I have single characters in the

  • 0

The problem I’m encountering with this is if I have single characters in the array $wordstodelete it then deletes them from words in the $oneBigDescription.

$oneBigDescription = str_replace ( $wordstodelete, '', $oneBigDescription);

So it makes it look like this:

array (size=51)
  'blck' => int 5
  'centrl' => int 6
  'clssc' => int 6
  'club' => int 10
  'crs' => int 54
  'deler' => int 7
  'delers' => int 5
  'engl' => int 6
  'felne' => int 8
  'gude' => int 5
  'hot' => int 5
  'jgur' => int 172
  'jgurs' => int 5
  'lke' => int 6

Is there a way to only delete the single character from $oneBigDescription if it is on its own?

  • 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-08T02:51:00+00:00Added an answer on June 8, 2026 at 2:51 am

    $oneBigDescription = preg_replace("/\b$wordstodelete\b/", '', $oneBigDescription);

    /b should look for word boundaries to ensure it’s an isolated word when one character is used.

    EDIT: Didn’t quite read that right – this is more assuming you’re looping over $wordstodelete as an array of words.

    So, something like this:

    $desc = "blah blah a b blah";
    $wordstodelete = array("a", "b");
    foreach($wordstodelete as $delete)
    {
        $desc= preg_replace("/\b$delete\b/", "", $desc);
    }
    

    EDIT2: Wasn’t quite happy with this, so refined slightly:

    $arr = "a delete aaa a b me b";
    $wordstodelete = array("a", "b");
    $regex = array();
    foreach($wordstodelete as $word)
    {
        $regex[] = "/\b$word\b\s?/";
    }
    $arr = preg_replace($regex, '', $arr);
    

    This account for taking out the following space, which in HTML isn’t usually an issue when rendered (since consecutive spaces aren’t generally rendered), but still a good idea to take it out. This also creates an array of regex expressions up front, which seems a bit nicer.

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

Sidebar

Related Questions

Problem: I have two array where one produce a category and the second produce
Problem! I Have the following input (rules) from a flat file (talking about numeric
Problem is like this: I have two winapi application's. There is only one way
Problem description I have 6 databases from 6 different machines, and having one cloud
Problem I have a Silverlight 5 application using the treeview from the SDK. Now
Problem: I have an address field from an Access database which has been converted
Problem: I have a table that prints out vertical but I would like it
Problem: I'm streaming my video from a php file with stream_get_contents(); using Flowplayer as
Problem Using Director 11.5 and Windows 7, with MouseWheel Xtra (wheelmouse.zip), I have the
Problem: I need an array (datamember) in a parent class A. However, depending on

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.