PHP ereg() Function Last Updated : 03 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ereg() function in PHP searches a string to match the regular expression given in the pattern. The function is case-sensitive. This function has been deprecated in PHP 5.3.0 and removed in PHP 7.0.0. Syntax: int ereg ( string $pattern , string $str, array &$arr ); Parameters: pattern: It is a regular case-sensitive expression.str: It is the input string.arr: It's an optional input parameter that contains an array of all matched expressions that were grouped by parentheses in the regular expression. Return value: If the pattern is found, the function will return true else false. It returns the length of the matched string if the pattern match was found in the string, or false if no match was found or an error occurred. The function returns 1 if the optional parameter arr has not been passed or the length of the matched string is 0. Example 1: In this example, the statement checks whether the subject provided to ereg() function contains .org or not. PHP <?php echo ereg("(\.)(org$)", "www.geeksforgeeks.org"); ?> Output: 1 Example 2: This example examines whether the subject begins with 'g' or not. The '^' symbol is used to check if the subject starts with the required string. PHP <?php echo ereg("g","gfg"); ?> Output: 1 Example 3: In this example, the following code snippet will take the date in DD-MM-YYYY format and print it in ISO format (YYYY-MM-DD). PHP <?php if (ereg ("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", "10-12-1999", $arr)) { echo "$arr[3]-$arr[2]-$arr[1]"; } else { echo "Invalid date format entered"; } ?> Output: 1999-12-10 Comment More infoAdvertise with us Next Article PHP mb_ereg() Function P priyavermaa1198 Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP mb_ereg() Function The mb_ereg() function is an inbuilt function in PHP that is used for searching a string in the multibyte string by using the regular expression. Syntax: mb_ereg($pattern, $string, $matches ): bool Parameters: The following function has three parameters that are described below. $pattern: The regula 1 min read PHP mb_eregi() Function The mb_eregi() function is an inbuilt function in PHP that performs case-insensitive regular expression matches on a string having multibyte support. If the string pattern is matched, then it will return the string otherwise it will return false. Syntax: mb_eregi( string $pattern, string $string, ar 2 min read PHP end() Function The end() function is an inbuilt function in PHP and is used to find the last element of the given array. The end() function changes the internal pointer of an array to point to the last element and returns the value of the last element.Syntax:end($array)Parameters:This function accepts a single par 2 min read PHP | exit( ) Function The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called. The message 2 min read PHP | exit( ) Function The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called. The message 2 min read PHP | ereg_replace() Function The ereg_replace() is an inbuilt function in PHP and is used to search a string pattern in an other string. If pattern is found in the original string then it will replace matching text with a replacement string. You may refer to the article on Regular Expression for basic understanding of pattern m 3 min read Like