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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:58:20+00:00 2026-06-17T12:58:20+00:00

str_replace($search, $replace, $subject); I have no problem with $search string and $replace string. But

  • 0
str_replace($search, $replace, $subject);

I have no problem with $search string and $replace string.

But how can I use str_replace() with $search string and $replace array?

  • 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-17T12:58:22+00:00Added an answer on June 17, 2026 at 12:58 pm

    The str_replace() documentation provides a clear example how to use arrays (of equal size):

    // Provides: You should eat pizza, beer, and ice cream every day
    $phrase  = "You should eat fruits, vegetables, and fiber every day.";
    $healthy = array("fruits", "vegetables", "fiber");
    $yummy   = array("pizza", "beer", "ice cream");
    
    $newphrase = str_replace($healthy, $yummy, $phrase);
    

    Using $search as a string and $replaces as an array is not possible and ‘weird’: which array value should be used for matches?

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

Sidebar

Related Questions

You can use arrays with str_replace(): $array_from = array ('from1', 'from2'); $array_to = array
In Php it's easy: str_replace (array(...), array(...), $subject) But how to do it in
I have a templating system for a current project. I use str_replace() to replace
Possible Duplicate: Search and replace inside an associative array I think this may have
I have a search strings and I need to replace search string character to
I am looking to search for and replace a known string from within another
$_GET['search'] = ucfirst(strtolower(str_replace(_, ,urldecode($_GET['search'])))); For some reason it's adding slashes into the string similar
I currently have this function to search and replace in a text file. //
i want to search the symbols \ and replace it by How can i
I have a search box where users can search for other users in a

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.