regular expression with ereg and eregi

[problem]

You want to perform regular expression with PHP.

[/problem]

[solution]

Again PHP implementation of regular expression is very similar to Perl.

In the simpliest form, pattern matching:

$ php -q<<EOT
<?php

$str="hello world";
if(ereg("world","$str")) {
echo("got a match");
}

?>
EOT

got a match

[/solution]

[example]

Similarly eregi operates the same, just it is case insensitive.

$ php -q<<EOT
<?php

$str=”hello world”;
if(eregi(“WORLD”,”$str”)) {
echo(“got a matchn”);
}

?>
EOT

got a match

[/example]

[reference]

[tags]PHP ereg, PHP eregi, PHP Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *