Solved

Array str_replace

Posted on 2013-11-10
5
245 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
  • 3
  • 2
5 Comments
 
LVL 108

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 108

Accepted Solution

by:
Ray Paseur earned 500 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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now