RE: [PHP] ereg_replace

From: Date: Thu, 15 Feb 2001 16:00:02 +0000
Subject: RE: [PHP] ereg_replace
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39921@lists.php.net to get a copy of this message
why does this <?php $string = "this is my string."; print $string . "<br>\n"; $string = preg_replace( array( '/is/', '/string/' ), array( 'is not', 'bit of text' ), $string ); print $string . "<br>\n"; ?> return this: this is my string. this not is not my bit of text. I was expecting: this is my string. this is not my bit of text. I'm obviously not understanding how this works..... -brian ************* > -----Original Message----- > From: Robin Vickery [mailto:robin@planet-three.co.uk] > Sent: Wednesday, February 14, 2001 5:05 AM > To: php-general@lists.php.net > Subject: Re: [PHP] ereg_replace > > > >>>>> ""VB" == "Brian V Bonini" > >>>>> <brian@gfx.cncdsl.com> writes: > > > I know you can replace A or B or C with D but can you replace A > > with B and C with D exclusively with one call to ereg_replace or > > does this need to be done seperately? > > With ereg_replace it must be done seperately, but if you use > preg_replace you can pass it a list of replacements. like this: > > <?php > $string = "this is my string."; > > print $string . "<br>\n"; > > $string = preg_replace( > array( '/my/', '/string/' ), > array( 'your', 'bit of text' ), > $string > ); > > print $string . "<br>\n"; > ?> > > The output would be: > > this is my string. > this is your bit of text. > > > -- > Robin Vickery................................................. > BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE > > -- > 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 (#39921) next »