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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:02:11+00:00 2026-05-31T06:02:11+00:00

Edit: The aim of my method is to delete a value from a string

  • 0

Edit: The aim of my method is to delete a value from a string in a database.

I cant seem to find the answer for this one anywhere. Can you concatenate inside a str_replace like this:

str_replace($pid . ",","",$boom);
  • $pid is a page id, eg 40
  • $boom is an exploded array

If i have a string: 40,56,12 i want to make it 56,12 however without the concatenator in it will produce:

,56,12

When I have the concat in the str_replace it doesnt do a thing. Is this possible?

  • 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-31T06:02:12+00:00Added an answer on May 31, 2026 at 6:02 am

    After you have edited it becomes clear that you want to remove the value of $pid from the array $boom which contains one number as a value. You can use array_search to find if it is in at if in with which key. You can then unset the element from $boom:

    $pid = '40';
    $boom = explode(',', '40,56,12');
    $r = array_search($pid, $boom, FALSE);
    if ($r !== FALSE) {
        unset($boom[$r]);
    }
    

    Old question:

    Can you concatenate inside a str_replace like this: … ?

    Yes you can, see the example:

    $pid = '40';
    $boom = array('40,56,12');
    print_r(str_replace($pid . ",", "", $boom));
    

    Result:

    Array
    (
        [0] => 56,12
    )
    

    Which is pretty much like you did so you might be looking for the problem at the wrong place. You can use any string expression for the parameter.

    It might be easier for you if you’re unsure to create a variable first:

    $pid = '40';
    $boom = array('40,56,12');
    $search = sprintf("%d,", $pid);
    print_r(str_replace($search, "", $boom));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: From another question I provided an answer that has links to a lot
Edit: I have solved this by myself. See my answer below I have set
My aim is to backup a database (.mdf) as one file with my web
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
EDIT: This peace of code is pretty fine (so take it as example of
My table is being populated using ajax from a mysql database. I have a
The aim I would like to set such size for the DataGrid (standard, from

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.