How can str_replace() be used in conjunction with regular expressions in PHP functions?
When using str_replace() in conjunction with regular expressions in PHP functions, you can search for patterns within a string and replace them with specified values. This can be useful for manipulating text data, such as formatting phone numbers or cleaning up user input. By using regular expressions in conjunction with str_replace(), you can perform more complex and flexible string manipulations.
$string = "Hello, my phone number is 123-456-7890.";
$pattern = '/[0-9]{3}-[0-9]{3}-[0-9]{4}/';
$replacement = 'XXX-XXX-XXXX';
$new_string = preg_replace($pattern, $replacement, $string);
echo $new_string;