PHP Terms Regular Expressions POSIX PHP Functions

 

- Info:

- PHP offers seven functions for searching strings using POSIX-style regular expressions:

ereg(), ereg_replace(), eregi(), eregi_replace(), split(), spliti(), and sql_regcase().

 

    

FUNCTION

DESCRIPTION

 

ereg()

Performs case sensitive search.

 

eregi()

Performs case insensitive search.

 

ereg_replace()

Replaces case sensitive search pattern with a replacement string.

 

eregi_replace()

Replaces case insensitive search pattern with a replacement string.

 

split()

Divides string between boundaries defined as sensitive pattern.

 

spliti()

Divides string between boundaries defined as insensitive pattern.

 

sql_regcase()

Converts each character into bracket containing two characters.

 

- Example:

- Create PHP Console Application Test.php.

 

Test.html

<?php

if (ereg ("[^a-z]" , "ivorONLINE")) { echo "String must be all lowercase!\n"; }

if (ereg ("^(ivor).*(INE)$", "ivorONLINE")) { echo "String starts with ivor and ends with INE\n";}

if (eregi("^(ivor).*(ine)$", "ivorONLINE")) { echo "String starts with ivor and ends with ine\n";}

echo ereg_replace ("[oN]","A","ivorONLINE\n"); //ivArOALIAE

echo eregi_replace("[on]","A","ivorONLINE\n"); //ivArAALIAE

$array = split ("[-,W]", "A-B,CWD"); print_r($array); //[A,B,C,D]

$array = spliti("[-,w]", "A-B,CWD"); print_r($array); //[A,B,C,D]

echo sql_regcase("php 4.0"); //[Pp][Hh][Pp] 4.0

?>