What is the function of eregi() in PHP and how can it be used to check for spaces in a string?

The eregi() function in PHP is used to perform a case-insensitive regular expression match. To check for spaces in a string using eregi(), you can use the regular expression pattern "/\s+/" which matches one or more whitespace characters. Example PHP code snippet:

$string = "This is a test string";
if (eregi("\s+", $string)) {
    echo "String contains spaces";
} else {
    echo "String does not contain spaces";
}