What is the significance of using Preg_Match in PHP for text manipulation?
Preg_match in PHP is significant for text manipulation because it allows you to search a string using a regular expression pattern. This is useful for tasks such as validating input, extracting specific information from a string, or performing complex search operations. By using preg_match, you can efficiently manipulate text based on specific patterns or criteria.
// Example of using preg_match to extract email addresses from a string
$string = "Contact us at email@example.com or support@example.com for assistance.";
$pattern = '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/';
preg_match_all($pattern, $string, $matches);
foreach ($matches[0] as $email) {
echo $email . "\n";
}