$text = 'I love apples.';
$replaced_text = str_replace('apples', 'oranges', $text);
echo $replaced_text;
Output
str_replace(
    array|string $search,
    array|string $replace,
    string|array $subject,
    int &$count = null
): string|array

// str_replace(search, replace, subject[, count]); 
$original_string = 'Hello, world! Hello, PHP!';
$new_string = str_replace('Hello', 'Hi', $original_string);

echo $new_string;  // Output: 'Hi, world! Hi, PHP!'
$str = 'This is a sample text.';
$new_str = str_replace('sample ', '', $str);
echo $new_str; // Output: 'This is a text.'
$original_array = [
    'Apples are red.',
    'Bananas are yellow.',
    'Apples and bananas are tasty.'
];

$search = ['Apples', 'Bananas'];
$replace = ['Oranges', 'Grapes'];

$new_array = str_replace($search, $replace, $original_array);

print_r($new_array);

/* Output:
Array
(
    [0] => Oranges are red.
    [1] => Grapes are yellow.
    [2] => Oranges and grapes are tasty.
)
*/
$original_string = 'Apples are red. Bananas are yellow. Apples and bananas are tasty.';

$search = ['Apples', 'Bananas'];
$replace = ['Oranges', 'Grapes'];

$new_string = str_replace($search, $replace, $original_string);

echo $new_string;
// Output: 'Oranges are red. Grapes are yellow. Oranges and grapes are tasty.'
$original_string = 'Hello world! Hello PHP! Hello everyone!';
$search = 'Hello';
$replace = 'Hi';
$count = 0;

$new_string = str_replace($search, $replace, $original_string, $count);

echo $new_string;  // Output: 'Hi world! Hi PHP! Hi everyone!'
echo "The word '{$search}' was found {$count} times.";
// Output: The word 'Hello' was found 3 times.