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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:34:41+00:00 2026-06-03T10:34:41+00:00

As given here str_replace() count parameter should stop if certain replacements are done. Right?

  • 0

As given here str_replace() count parameter should stop if certain replacements are done. Right?

Here is my code:

define("PLACEHOLDER", "INSERT INTO `listings` VALUES (NULL, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');".PHP_EOL);
$r = (4 - count($_POST['ad']));
print count($_POST['ad'])."\n";
print $r;
$pf_args = str_replace("'%s', ", "", PLACEHOLDER, $r);
print $pf_args;

Now I double-checked everything that $r = 1 in one my test and to be doubly sure count($_POST['ad']) is 3. Still, str_replace completely ignores count parameter and replaces all occurances to give:

INSERT INTO `listings` VALUES (NULL, '%s');

This is driving me insane. Having seen so much anti-php talks, such eccentric behaviour(s) mkes me feel that they are bugs or another one of those weird magic it possesses.

  • 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-03T10:34:43+00:00Added an answer on June 3, 2026 at 10:34 am

    I believe $count is used to check how many replacements were performed (for example, if you printed $count after using str_replace(), you would get 10).

    You could do what you want to do by using preg_replace() with a little regex. Please see: How to use str_replace() to remove text a certain number of times only in PHP?

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

Sidebar

Related Questions

For example, my goal is to test the code given here: PHP script that
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>
Here I have 2 methods using str_replace to replace strings in a given phrase.
Here is my code: # Given an Unix timestamp in milliseconds (ts), return a
Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx I'm trying to use the datacontext between
I am trying to use the solution given here -> C# ADO.NET: nulls and
I am trying to do work with examples on Trees as given here: http://cslibrary.stanford.edu/110/BinaryTrees.html
I compute c = a 'OR' b // bitwise OR operation here Now given
Here's what I want to do: Given a table PeopleOutfit (id int primary key,
Here is my problem: Create a constructor for a telephone number given a string

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.