regular expression with ereg and eregi

Problem

You want to perform regular expression with PHP.



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



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



Reference

Technorati Tags: , ,



Most Viewed


Leave a Reply


Search engine optimization by SEO Design Solutions