PHP Classes
elePHPant
Icontem

File: tests/condition2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Marco Marchiņ  >  Regexp Builder  >  tests/condition2.php  >  Download  
File: tests/condition2.php
Role: Example script
Content type: text/plain
Description: Condition test 2
Class: Regexp Builder
Build regular expressions programmatically
Author: By
Last change: .
Date: 5 years ago
Size: 814 bytes
 

Contents

Class file image Download
<?php
require_once "../regexpBuilder.php";
/*
Match every "cat" then if it is preceeded by "dog" than match "run" otherwise match "eat"
LOGIC:
- open capture
- match "cat"
- start condition
- if it's preceeded by "dog"
- then match "run"
- otherwise match "eat"
- close condition
- close capture
*/

$regexp=new regexpBuilder();
$regexp->capture() //open capture
->match("cat") //match "cat"
->ifItIs(PRECEEDED_BY) //start condition
->match("dog".SPACE_CHAR) //if it's preceeded by "dog"
->then()->match(SPACE_CHAR."run") //then match "run"
->otherwise()->match(SPACE_CHAR."eat") //otherwise match "eat"
->closeIf() //close condition
->closeCapture(); //close capture

$matches=$regexp->execOn("dog cat run, mouse cat eat");
print_r($matches[1]);
//[0] => cat run
//[1] => cat eat
?>