RE: [PHP] string replace using ereg

From: Date: Mon, 16 Jul 2001 17:16:21 +0000
Subject: RE: [PHP] string replace using ereg
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-58087@lists.php.net to get a copy of this message
what code are you trying to use? i have exactly the following code, and it prints out: Hello there, this is a test. My name is BOB $text = "Hello there, <<test>>. My name is <<name>>"; $ASSIGN = array(test => "this is a test", 'name'=> 'BOB', ); $OPENTAG = "<<"; $CLOSETAG = ">>"; print preg_replace( "/$OPENTAG(.*?)$CLOSETAG/e", '$ASSIGN[$1]', $text ); > -----Original Message----- > From: Jeroen Olthof [mailto:j.olthof@millipede.nl] > Sent: Monday, July 16, 2001 12:45 PM > To: scott@graphictype.com > Subject: Re: [PHP] string replace using ereg > > > Mmmm, thx , but I can't get it to work when I run your code, > > Parse error: parse error, expecting T_VARIABLE' or > '$'' in Eval code on > line 1 > > Fatal error: Failed evaluating code: $ASSIGN[$1] in test2.php on line 9 > > ? > can u please take another small look > > thanks anyway > > "Scott" <scott@graphictype.com> schreef in bericht > > news:<KFEKLFMNHDILCMFAEKJCKEKKCNAA.scott@graphictype.com>... > > $text = "Hello there, <<test>>. > > My name is <<name>>"; > > > > $ASSIGN = array(test => "this is a test", 'name'=> > > 'BOB', ); > > $OPENTAG = "<<"; > > $CLOSETAG = ">>"; > > > > print preg_replace( "/$OPENTAG(.*?)$CLOSETAG/e", '$ASSIGN[$1]', $text > > ); > > > > > > prints: > > Hello there, this is a test. > > My name is BOB > > > > > > To do what you want, throw a loop statement around the preg_replace > > to loop thru each line of a file... etc... :) > > > > > -----Original Message----- > > > From: Jeroen Olthof [mailto:j.olthof@millipede.nl] > > > Sent: Monday, July 16, 2001 12:01 PM > > > To: php-general@lists.php.net > > > Subject: [PHP] string replace using ereg > > > > > > > > > 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]); > > > } > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > >

« previous php.general (#58087) next »