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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:13:53+00:00 2026-05-31T07:13:53+00:00

Basically I have a situation like this: $search = array( ‘?’, ‘?’ ); $replace

  • 0

Basically I have a situation like this:

$search = array(
   '?',
   '?'
);

$replace = array(
   '1',
   '2'
);

When I try:

str_replace($search,$replace,"First value: ? Second Value: ?");

I get:

"First value: 1 Second Value: 1"  //> Notice the "1" repetead

Instead of

 "First value: 1 Second Value: 2"

How could I get the second result (even without the use of str_replace)?

  • 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-31T07:13:54+00:00Added an answer on May 31, 2026 at 7:13 am

    preg_replace has a limit parameter so you can use that instead:

    $search = array(
       '/\?/',
       '/\?/'
    );
    
    $replace = array(
       '1',
       '2'
    );
    
    echo preg_replace($search, $replace, "First value: ? Second Value: ?", 1);
    
    // output: First value: 1 Second Value: 2
    

    You can use array_fill to build the search array:

    preg_replace(array_fill(0, count($replace), '/\?/'), $replace, $subject, 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically the situation is like this (simplified, pseudo code): I have 2 TABLES person
I'm pulling a content from PHP array and I have a situation like this:
i have this situation: print_r($key);echo'<br>'; foreach($value as $test){ print_r(count($test));echo'<br>'; } echo'<br>'; witch returns: Jerome
The topic generically says it all. Basically in a situation like this: boost::scoped_array<int> p(new
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have the same question as this guy .. The example in the
I have this error that is keeping me from moving forward. I basically have
So I keep having this small problem where I have something like func ::
This is an extremely common situation, so I'm expecting a good solution. Basically we
I have a situation like below in which I have some problem in freeing

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.