PHP Classes

File: tests/replace_function.php

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


Class file image Download
require_once "../regexpBuilder.php";
Replace with function test. Increase every number in the string.
Format: Today is 09/11/2009

- find every number repeated one ore more times
- increase and return it with a function
$regexp=new regexpBuilder();
$regexp->match(DIGIT_CHAR)->oneOrMoreTimes(); //find every number repeated one ore more times

$callback=create_function('$match','return (int)$match[0]+1;');
$result=$regexp->replaceWithCallback($callback,"Today is 09/11/2009");
"Today is 09/11/2009<br>Result: ".$result; //Result: Today is 10/12/2010