Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Below example shows the alternative method in preg functions

ereg functionsRecommended recommended alternative functions

eregi( string $pattern , string $string ) : int

Code Block
$source = "My email address is Chun Kang<ck@qsok.com>.";
if (ereg("email", $source)) {
  echo "the source has 'email' on the content";
}


preg_match( string $pattern , string $subject ) : int

Code Block
$source = "My email address is Chun Kang<ck@qsok.com>.";
if (preg("/email/", $source)) {
  echo "the source has 'email' on the content";
}


eregi( string $pattern , string $string ) : int

Code Block
$source = "My email address is Chun Kang<ck@qsok.com>.";
if (eregi("chun kang", $source)) {
  echo "the source has 'chun kang' on the content";
}


preg_match( string $pattern , string $subject ) : int


Code Block
$source = "My email address is Chun Kang<ck@qsok.com>.";
if (preg_match("/Chun Kang/i", $source)) {
  echo "the source has 'email' on the content";
}


eregi( string $pattern , string $string , array &$regs ) : int

Code Block
$source = "My email address is Chun Kang<ck@qsok.com>.";
if (eregi("<(.*)@(.*)>", $source, $output)) {
	print_r($output);
}

Result

Code Block
Array
(
    [0] => <ck@qsok.com>
    [1] => ck
    [2] => qsok.com
)


preg_match( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) : int

Code Block
if (preg_match("/<(.*)@(.*)>/i", $source, $output)) {
	print_r($output);
}

Result

Code Block
Array
(
    [0] => <ck@qsok.com>
    [1] => ck
    [2] => qsok.com
)


...