I'm trying to replace 2 parts of a javascript code line1 line2 $function preg_replace(find, replace, ''); echo $function; How do I write the same code to replace line 2, which will look for a different item and replace it with something different
You probably don't even need preg_replace(). You should use str_replace() if you know exactly what you are looking as it will be faster. $strJavaScript = <<<EOF // Insert a whole bunch // of JavaScript here EOF; $strSearch1 = '** Edit: Script code to find **'; $strSearch2 = '** Edit: More script code to find **'; $strReplace1 = '** Edit: New value for $Search1 **'; $strReplace2 = '** Edit: New value for $Search2 **'; print(str_replace( array($strSearch1, $strSearch2), array($strReplace1, $strReplace2), $strJavaScript); Code (markup): If you actually need regular expression pattern matching then do this: $strJavaScript = <<<EOF // Insert a whole bunch // of JavaScript here EOF; $strSearch1 = '** Edit: Script to find **'; $strSearch2 = '** Edit: More sript to find **'; $strReplace1 = '** Edit: New value for $Search1 **'; $strReplace2 = '** Edit: New value for $Search2 **'; print(ereg_replace( $strSearch1, $strReplace1, ereg_replace( $strSearch2, $strReplace2, $strJavaScript)); Code (markup):