string replace using ereg

From: Date: Mon, 16 Jul 2001 16:01:29 +0000
Subject: string replace using ereg
Groups: php.general 
Request: Send a blank email to php-general+get-58073@lists.php.net to get a copy of this message
hi, I want to replace strings in string using a key / value array as the replacemant contract basicly, I want to find a open en close tag, pick out the word in the middle and replace it by the value of the key that match the picked out word. example <<test>> <<test>> should result in this is a test this is a test well, The below code works for only one replacement cause when I add another on the same line. it will pick out test>> <<test als the key wordt and therefor isn't able to find this key in the array. how can I get the reg expression so it will not only get the first occurence of the open tag and the last of the close tag ?? please help, kind regards Jeroen Olthof $ASSIGN = array(test => "this is a test" ) $OPENTAG = "<<"; $CLOSETAG = ">>"; while ($line[$i]) { ereg($OPENTAG."([^*]*)".$CLOSETAG, $line[$i], $regs); $newString .= str_replace($this->OPENTAG.$regs[1].$this->CLOSETAG, $ASSIGN[$regs[1]], $line[$i]); }

« previous php.general (#58073) next »