What are the differences between ereg and eregi functions in PHP, and when should each be used?
The main difference between ereg and eregi functions in PHP is that ereg is case-sensitive, while eregi is case-insensitive. You should use ereg when you want to perform a case-sensitive search, and eregi when you want to perform a case-insensitive search.
// Using ereg for case-sensitive search
if (ereg("hello", $string)) {
echo "Found 'hello' in the string.";
}
// Using eregi for case-insensitive search
if (eregi("world", $string)) {
echo "Found 'world' in the string.";
}