Thursday, October 1, 2020

PHP eregi() Function



Hello dear readers! welcome back to another section of my tutorial on PHP. In this tutorial guide, we will be discussing about the PHP eregi() Function.

The PHP eregi() function searches throughout a string specified by pattern for a string specified by string. Search with this function is not case sensitive. The eregi() can be specifically very useful when checking for the validity of strings, such as password.

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

RECOMMENDED POST: PHP ereg_replace() Function

Syntax

The following is the syntax for the eregi() function -

int eregi(string pattern, string string, [array regs]);

Return Value

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

Example

Following is a simple example -

<?php
   $password = "abc";
   
   if (! eregi ("[[:alnum:]]{8,10}", $password))
   {
      print "Invalid password! Passwords must be from 8 - 10 chars";
   } else {
      print "Valid password";
   }
?>

Output

When the above code is executed, it will produce the following result -

Invalid password! Passwords must be from 8 - 10 chars

RECOMMENDED POST: PHP ereg() Function

Alright guys! This is where we are rounding up for this tutorial post. In my next tutorial guide, we are going to be discussing about the PHP eregi_replace() Function.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.
Share:

0 comments:

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.