Complete the code to replace all digits with a dash using preg_replace.
<?php $text = "Call me at 123-456-7890."; $result = preg_replace([1], '-', $text); echo $result; ?>
The pattern /\d/ matches any digit. Using it in preg_replace replaces all digits with '-'.
Complete the code to replace all vowels with '*' using preg_replace.
<?php $text = "Hello World!"; $result = preg_replace([1], '*', $text); echo $result; ?>
The pattern /[aeiou]/i matches vowels ignoring case. It replaces vowels with '*'.
Fix the error in the code to replace all spaces with underscores using preg_replace.
<?php $text = "Replace spaces here."; $result = preg_replace([1], '_', $text); echo $result; ?>
The pattern /\s/ matches any whitespace character including spaces. It replaces spaces with underscores.
Fill both blanks to replace all words starting with 'a' or 'A' with 'word' using preg_replace.
<?php $text = "An apple a day keeps the doctor away."; $result = preg_replace([1], [2], $text); echo $result; ?>
The pattern /\b[aA]\w*/ matches words starting with 'a' or 'A'. Replacing with 'word' substitutes those words.
Fill all three blanks to replace all digits with '#' only if they are at the start of the string using preg_replace.
<?php $text = "123abc456"; $result = preg_replace([1], [2], $text, [3]); echo $result; ?>
The pattern /^\d+/ matches digits at the start. Replacement is '#'. Limit 1 ensures only the first match is replaced.