PHP Classes

File: tests/grep.php

Recommend this page to a friend!
  Classes of Marco Marchiņ   Regexp Builder   tests/grep.php   Download  
File: tests/grep.php
Role: Example script
Content type: text/plain
Description: Grep example
Class: Regexp Builder
Build regular expressions programmatically
Author: By
Last change:
Date: 14 years ago
Size: 671 bytes
 

Contents

Class file image Download
<?php
require_once "../regexpBuilder.php";
/*
Get every string that contains only letters:
Format: array("abc"," ",".","def","");

LOGIC:
- match line start
- match letters repeated one or more times
- match line end
- grep
*/

$regexp=new regexpBuilder();
$regexp->matchLineStart() //match line start
->matchOneOfTheseChars(LETTER_CHAR)->oneOrMoreTimes() //match letters repeated one or more times
->matchLineEnd(); //match line end

$input=array("abc"," ",".","def","");
$result=$regexp->grep($input);

echo
"Test: array(\"abc\",\" \",\".\",\"def\",\"\");<br>";
echo
"Result: ".print_r($result,true)."<br>"; //Array ( [0] => abc [3] => def )
?>