Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Array str_replace

Posted on 2013-11-10
5
Medium Priority
?
274 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.
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 …
Suggested Courses

597 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