Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/replace.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.php  >  Download  
File: tests/replace.php
Role: Example script
Content type: text/plain
Description: Replace example
Class: Regexp Builder
Build regular expressions programmatically
Author: By
Last change:
Date: 4 years ago
Size: 530 bytes
 

Contents

Class file image Download
<?php
require_once "../regexpBuilder.php";
/*
Replace function test. Replace every space with the space character in html format (&nbsp;).
Format: This is a test
LOGIC:
- find space charachter repeated one or more times
- replace with &nbsp;
*/

$regexp=new regexpBuilder();
$regexp->match(SPACE_CHAR)->oneOrMoreTimes();    //find space charachter repeated one or more times

$result=$regexp->replaceWith("&nbsp;","This is a test");
echo 
"This is a test<br>Result: ".$result//Result: This&nbsp;is&nbsp;a&nbsp;test
?>