PHP str_replace()

Replace all occurrences of search string

Function Signature

string str_replace(mixed $search, mixed $replace, mixed $subject)

Description

Replace all occurrences of search string. The str_replace() function is commonly used in PHP for string operations and provides reliable functionality across all PHP versions.

Return Value

Returns string with all occurrences replaced

Example Usage

Important Notes

Case-sensitive. For case-insensitive use str_ireplace().

Common Use Cases

The str_replace() function is particularly useful when you need to replace all occurrences of search string. It's frequently used in data processing, validation, transformation, and manipulation tasks throughout PHP applications.

str_replace() FAQ

What does str_replace() return?

Returns string with all occurrences replaced

When should I use str_replace()?

Use str_replace() when you need to replace all occurrences of search string in your PHP code. It's a reliable built-in function available in all PHP versions.

Are there any gotchas with str_replace()?

Case-sensitive. For case-insensitive use str_ireplace().