How can the second parameter of preg_replace be used to convert a match to lowercase? Is preg_replace_callback the only option for this?

To convert a match to lowercase using the second parameter of preg_replace, you can use the following syntax: '\L'. This tells preg_replace to convert the matched substring to lowercase. However, if you need more complex logic or dynamic conversions, preg_replace_callback can be used as an alternative option.

// Using preg_replace to convert a match to lowercase
$text = "Hello World";
$pattern = '/\b(\w+)\b/';
$replacement = '\L$1';
$result = preg_replace($pattern, $replacement, $text);
echo $result; // Output: hello world