Solved

Array str_replace

Posted on 2013-11-10
5
250 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 109

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 109

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 109

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 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