Solved

Array str_replace

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

830 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