Skip to content

Instantly share code, notes, and snippets.

@weatheredwatcher
Created October 8, 2012 17:17
Show Gist options
  • Save weatheredwatcher/3853696 to your computer and use it in GitHub Desktop.
Save weatheredwatcher/3853696 to your computer and use it in GitHub Desktop.
A basic test for regular expressions
function isTable($string) {
if (preg_match("/^cms_/i", $string)) { //this is where you place the regex that you want to test
return TRUE;
} else {
return FALSE;
}
}
$string= ["cms_phone_apps", "cms_phone", "cms phone", "phone_cms"]; //using php 5.4's new array syntax rocks!
// we set two counters to count how many true/false we get for our expressions
$is=0;
$isnot=0;
foreach ($string as $key => $value):
if(isTAble($value)):
echo $value.":It is a table\n";
$is++;
else:
echo $value.":It is not a table\n";
$isnot++;
endif;
endforeach;
if($is == 2 && $isnot == 2): //here we setup howmany true/false we expect and set a pass/fail return on our test
echo("PASS");
else:
echo("FAIL");
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment