From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Multiple string replacement and SVGs

Multiple string replacement and SVGs

From the course: PHP Tips, Tricks, and Techniques

Multiple string replacement and SVGs

- [Instructor] Hi, I'm David Powers, and welcome to this week's edition of PHP Tips and Tricks, designed to help you become a smarter, more productive PHP developer. In this edition, I want to focus on an often overlooked aspect of the str_replace function, the ability to replace multiple character strings in a single pass, and I'll use this feature to generate data URIs for scalable vector graphics. This is the documentation of a str_replace in the PHP online manual. The function's signature shows that the data type for the three required arguments is mixed. This means they can either be a single string or an array of strings. In the case of this third argument, the subject that's being edited, it enables you to do a find and replace operation on every element of an array. Now, that's certainly useful, but I think that much more interesting is using arrays for the first two arguments, for search and for replace. Instead of finding and replacing one string at a time, you can pass an…

Contents