PHP preg_replace or str_replace

benhoffman

New Member
I have some text, something like this:\[code\]Paragraphs of text(SOME KNOWN TEXT)Unknown Text(SOME OTHER KNOWN TEXT)Some additional paragraphs of text\[/code\]What I want is to keep the Unknown Text, but get rid of the (SOME KNOWN TEXT) and (SOME OTHER KNOWN TEXT).I think the preg_replace will give me what I want, but I need the regular expression to replace this:\[code\](SOME KNOWN TEXT)Unknown Text(SOME OTHER KNOWN TEXT)\[/code\]with this ..\[code\]Unknown Text\[/code\]I see the preg_replace takes 3 parameters, the regex, the replacement text, and subject.Is there a way to pass the value of unknown text to the replacement text parameter, OR, a way to reaplce the left and right pieces (SOME KNOWN TEXT) and (SOME OTHER KNOW TEXT) without removing the Unknown Text? Alternatively, is there a str_replace() solution to this?Thanks---UPDATE---The (SOME OTHER KNOWN TEXT) piece may exist in other places in the text, but I don't want it removed unless it follows the pattern of (SOME KNOWN TEXT)Unknown Text(SOME OTHER KNOWN TEXT). I am thinking the initial str_replace suggestions would not work because of this.
 
Top