?
Solved

Array str_replace

Posted on 2013-11-10
5
Medium Priority
?
265 Views
Last Modified: 2013-11-11
Does str_replace with an array only work on a row by row basis?
And when using it is there a way to say only if match the whole contents and not a partial match on the array element.
0
Comment
Question by:Gary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39637710
"With an array" is ambiguous.  The arguments can be strings or arrays.
http://php.net/manual/en/function.str-replace.php

The simplest rules are all you get with str_replace() so if you want greater specificity your best choice is preg_replace()
0
 
LVL 58

Author Comment

by:Gary
ID: 39637717
It's thousands of rows in an array and each row has about 20 elements.
I'm thinking it might be easier to just load the file into a string and do a mass replace on everything I need replaceing and then parse it into an array.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39637754
There is likely no observable performance difference.  I would choose the way that makes the most sense programatically.  Anything that numbers in the thousands is easy to overlook in terms of elapsed execution time.  If you want to post some sample test data I'd be glad to show you how I might try the replacements.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39639224
Thanks for the points, ~Ray
0
 
LVL 58

Author Comment

by:Gary
ID: 39639281
I would choose the way that makes the most sense programatically
Doing a mass replace (using the delimiter to identify the whole field) is a lot easier than trying to process on an element by element and row by row basis - just thinking about coding that made the mass replace the best route (which takes one line).
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question