PHP Classes

File: tests/condition2.php

Recommend this page to a friend!
  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: 14 years ago
Size: 814 bytes


Class file image Download
require_once "../regexpBuilder.php";
Match every "cat" then if it is preceeded by "dog" than match "run" otherwise match "eat"
- 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");
//[0] => cat run
//[1] => cat eat