• PHP Video Tutorials

PHP - Function ereg()


Advertisements

Syntax

int ereg(string pattern, string originalstring, [array regs]);

Definition and Usage

The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise. The search is case sensitive in regard to alphabetical characters.

The optional input parameter regs contains an array of all matched expressions that were grouped by parentheses in the regular expression.

Return Value

  • It returns true if the pattern is found, and false otherwise.

Example

Following is the piece of code, copy and paste this code into a file and verify the result.

<?php
   $email_id = "admin@tutorialspoint.com";
   $retval = ereg("(\.)(com$)", $email_id);
   
   if( $retval == true )
   {
      echo "Found a .com<br>";
   } else {
      echo "Could not found a .com<br>";
   }
	
   $retval = ereg(("(\.)(com$)"), $email_id, $regs);
   
   if( $retval == true )
   {
      echo "Found a .com and reg = ". $regs[0];
   } else {
      echo "Could not found a .com";
   }
	
?>

This will produce the following result −

Ereg
php_regular_expression.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements