Question #224
Submitted by Answiki
on 11/23/2020 at 08:16:10 PM UTC
In PHP, how to replace a substring in a string?
Merged questions
Answer
Submitted by Answiki
on 11/23/2020 at 08:23:05 PM UTC
The PHP function str_replace($substring, $replace, $string) returns the string $string with all substrings $substring replaced by $replace. Here is an example :
// Original string
$phrase = "To be or not to be.";
// Replace 'be' by 'eat' in the string
$newPhrase = str_replace('be', 'eat', $phrase);
// Displays: To eat or not to eat.
echo $newPhrase;
Question by Answiki 10/12/2021 at 06:58:23 PM
How to replace a substring in a string in PHP?
Answer by Answiki on 11/23/2020 at 08:23:05 PM
The PHP function str_replace($substring, $replace, $string) returns the string $string with all substrings $substring replaced by $replace. Here is an example :
// Original string
$phrase = "To be or not to be.";
// Replace 'be' by 'eat' in the string
$newPhrase = str_replace('be', 'eat', $phrase);
// Displays: To eat or not to eat.
echo $newPhrase;
Question by Answiki 11/23/2020 at 08:16:10 PM
In PHP, how to replace a substring in a string?
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 13688 | alphons | https://en.ans.wiki/224/in-php-how-to-replace-a-substring-in-a-string | 1 |
| 1 | 12961 | en | https://en.ans.wiki/224/in-php-how-to-replace-a-substring-in-a-string | 6 |
Icons proudly provided by Friconix.