hi RE gurus, i have a string "before [hide] some secret words [/hide] after" how can i use preg_replace and return the two strings below 1. "before -- reply to view content -- after" 2. "before some secret words after" Thanks for guiding
<?php $string = <<<STRING before [hide] some secret words [/hide] after STRING; //outputs - "before -- reply to view content -- after" $string1 = preg_replace("@\[hide\](.*)\[/hide\]@", "-- reply to view content --", $string); //outputs - "before some secret words after" $string2 = preg_replace("@\[hide\]|\[/hide\]@", "", $string); ?> PHP:
I think on the string1 one he wants to get rid of the text between the faux tags and replace them with a constant string.
Sure add the 's' modifier. <?php $string = <<<STRING 'start hide topic [hide] somehid decontent [/hide] after STRING; //outputs - "before -- reply to view content -- after" $string1 = preg_replace("@\[hide\](.*)\[/hide\]@s", "-- reply to view content --", $string); //outputs - "before some secret words after" $string2 = preg_replace("@\[hide\]|\[/hide\]@s", "", $string); echo $string1; ?> PHP: