Re: replacing everything between 2 strings

From: Date: Tue, 22 Jul 2003 02:02:13 +0000
Subject: Re: replacing everything between 2 strings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-156174@lists.php.net to get a copy of this message
>>>>> "Matt" == Matt Palermo <mpalermo@vt.edu> writes: Matt> Is there a way to replace everything between 2 given strings Matt> if it exists? Say I have: Matt> $str = "replace anything and everything in here."; Matt> Now I want to replace everything between the word "replace" Matt> and "here.", so the new string could read something like Matt> this: Matt> $str = "replace NOTHING here."; how about something like this (untested) $newStr= preg_replace("/^(replace).*(here)$/", "${1} NOTHING ${2}", $str); sort of like in the manual: http://www.php.net/manual/en/function.preg-replace.php --

« previous php.general (#156174) next »