Hey everyone,
I have a class that has the following function in it:
Class myclass(){
var $number;
var $title;
var $artist;
var $tim;
/**************************************************************
*
* parseif function -
* Checks for the function
%if%(%number%)?Truepart:falsepart%if%, evaluates it
* and returns a proper replacment for the string.
* It Returns the string with the proper replacment
* if you have %if%(%number%)?Truepart:Falsepart%if% it will
either return
* Truepart
* or
* Falsepart
*
* depending on weather or not $this->number is a real value or
not
* if you have "a
href=\"classwrapper.php?thing=play&id=%number%\">%artist% - %title%
%if%(%time%)?(%time% Minutes):"%if%</a>"
* it will return:
* "a href=\"classwrapper.php?thing=play&id=%number%\">%artist%
- %title% (%artist% Minutes) </a>"
* or
* "a href=\"classwrapper.php?thing=play&id=%number%\">%artist%
- %title% </a>"
*
**************************************************************/
function parseif($string,$ValueToReplace){
if($this->debug){print $this->debugbeg ."ParseIf<HR>";}
$replacement['title'] =1;
$replacement['artist'] =2;
$replacement['tim'] =3;
$replacement['number'] =4;
$RegExPattern = "/(.*)". // First part of the
string
"%([a-z]{1,3})%". // if
"\(%([a-z]{1,10})%\)". // Variable
"(\W{0,1})". // ?
"(.*)".
"(.*):". // rest of string
"(.*)". //
"%([a-z]{1,3})%". // if
"(.*)/i"; // string after end
of if statement
if($this->verbose){
print nl2br("RegEx ~$RegExPattern~\nstring before...
'$string'\n");
}
$th = $err = preg_match($RegExPattern,$string,$answer);
if($this->verbose){
print_r($answer);
}
if($answer[3] == "time"){
$answer[3] = "tim";
}
$torep = $replacement[$answer[3]];
$torep = $torep -1;
if(!isset($ValueToReplace[$torep]) or
$ValueToReplace[$torep] != ""){
$string = $answer[1] . $answer[5] . $answer[9];
}else{
$string = $answer[1] . $answer[7] . $answer[9];
}
if($this->debug){
if($this->verbose){
print nl2br("\$ValueToReplace['{$torep}'] = '".
$ValueToReplace[$torep] ."'\n");
print nl2br("string after... '$string'\n");
}
print "returning $string<br>\n" . $this->debugend
."<br>";
}
return $string;
}
}
I was just wondering if there was a better way to do this or if this is
about the right way to do it.
Thank You,
Mike
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php