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
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
- Tip_18.zip
- Tip_19.zip
- Tip_01.zip
- Tip_20.zip
- Tip_02.zip
- Tip_25.zip
- Tip_03.zip
- Tip_21.zip
- Tip_22.zip
- Tip_04.zip
- Tip_23.zip
- Tip_24.zip
- Tip_06.zip
- Tip_07.zip
- Tip_34.zip
- Tip_30.zip
- Tip_31.zip
- Tip_14.zip
- Tip_32.zip
- Tip_17.zip
- Tip_33.zip
- Tip_29.zip
- Tip_35.zip
- Tip_36.zip
- Tip_37.zip
- Tip_09.zip
- Tip_10.zip
- Tip_38.zip
- Tip_39.zip
- Tip_40.zip
- Tip_08.zip
- Tip_26.zip
- Tip_11.zip
- Tip_12.zip
- Tip_13.zip
- Tip_15.zip
- Tip_16.zip
- Tip_28.zip
Contents
-
-
-
Round numbers to a specific multiple6m 57s
-
Array dereferencing4m 55s
-
Variable functions6m 8s
-
Build nested unordered lists automatically8m 56s
-
Display a repeating value only once4m 43s
-
Batch convert images to data URIs8m 18s
-
Multiple string replacement and SVGs8m 45s
-
Prevent cross-site script attacks in forms9m 39s
-
Changes to calculations with strings7m 35s
-
Unpacking arrays in PHP 7.17m 46s
-
User authentication with password hashing9m 20s
-
Set a future date7m 40s
-
Block access to expired member10m 55s
-
Extract complete sentences from start of text8m 48s
-
Prevent email header injection attacks7m 17s
-
Variable variables6m 47s
-
Select files for archiving9m 58s
-
Set a time limit on a session7m 27s
-
Custom sort an array with the spaceship operator7m 26s
-
Understanding the splat operator8m 55s
-
Converting new lines to real paragraphs7m 36s
-
Introducing PHP generators9m 33s
-
Dynamically editing a CSV file9m 32s
-
Finding all links in a webpage7m 35s
-
Creating a download link9m 45s
-
Debugging PDO prepared statements5m 59s
-
Time is running out for PHP 54m 43s
-
Extract values with a format string9m 10s
-
Generate harmonious color tones8m 7s
-
Getting all possible permutations of an array5m 39s
-
Merging arrays5m 57s
-
Strip accents from text9m 29s
-
Export associative arrays from a CSV6m 57s
-
Export spreadsheet data to a multi-table database10m 38s
-
Validate email address with accented characters3m 33s
-
Generating random numbers and strings7m 54s
-
Shorthand conditional expressions9m 9s
-
Modifying each element in an array8m 36s
-
Smart quotes and apostrophes7m 52s
-
Shortest distance between two locations6m 55s
-