Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/replace_function.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/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: 4 years ago
Size: 594 bytes
 

Contents

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

LOGIC:
- 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");
echo 
"Today is 09/11/2009<br>Result: ".$result//Result: Today is 10/12/2010
?>