PHP Classes
Icontem

File: alter1.6.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alexander Amzin  >  Alternate text  >  alter1.6.php  
File: alter1.6.php
Role: Class source
Content type: text/plain
Description: Version 1.6 of class - now with regexps
Class: Alternate text
Alternative strings; (string1|string2|string3)...
 

Contents

Class file image Download
<?
// Class dealing with alternative strings:
// version 1.6 - now with regexps
// String Syntax: some text (h|e|e|l|l|l|l|o| |,|world) some text    
class alternate {
  var 
$s;
var 
$pattern;

        function 
ms () {
//seeding
        
list($usec$sec) = explode(' 'microtime());
        return (float) 
$sec + ((float) $usec 100000);
        
srand(make_seed());

            }
    function 
bracket ($str) {
    
//returns bracket code
     
if (!strcmp($str,"(")) {return 1;}
     elseif (!
strcmp($str,")")) {return -1;} else {return 0;}

                }

    function 
alternate ($s="") {
    
$this->ms();
    
$this->s=$s;
    
$this->pattern="/\(([^\(]*?)\)/m";
    while (
preg_match($this->pattern,$this->s)!=0)
    
$this->s=preg_replace_callback ($this->pattern
    
create_function (
    
'$matches'
    
'$store=explode("|",$matches[1]);
    $store=explode("|",$matches[1]);
    $rand_key=$store[array_rand($store,1)];
    return $rand_key;'
),
    
$this->s);
   }
}


$alter=new alternate ("Running script\n((ha\nil|cr\ny|hello), (world|gold|silver)|how do you (do|did|man)?|anybody here?)");
echo 
$alter->s;

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products