newbtophp Posted December 8, 2009 Share Posted December 8, 2009 Hmm im having abit of trouble, how would i replace: ;echo ' '; (contains a new line after opening quote). with: ?> <?php Example: <?php include("../config.php"); ;echo ' '; $variable = "test"; echo $variable; ?> Would turn into: <?php include("../config.php"); ?> <?php $variable = "test"; echo $variable; ?> :-\ Link to comment https://forums.phpfreaks.com/topic/184425-preg_replace-trouble/ Share on other sites More sharing options...
newbtophp Posted December 8, 2009 Author Share Posted December 8, 2009 My try - altough no luck: $variable = preg_replace("#;echo '[\s]';#", "?>\r\n<?php", $variable); Link to comment https://forums.phpfreaks.com/topic/184425-preg_replace-trouble/#findComment-973547 Share on other sites More sharing options...
salathe Posted December 8, 2009 Share Posted December 8, 2009 Do you really need a regular expression? $variable = str_replace(";echo '\n';", "?>\n<?php", $variable); (If the string contains \r\n style newlines, use that instead of just \n.) Link to comment https://forums.phpfreaks.com/topic/184425-preg_replace-trouble/#findComment-973605 Share on other sites More sharing options...
newbtophp Posted December 8, 2009 Author Share Posted December 8, 2009 Do you really need a regular expression? $variable = str_replace(";echo '\n';", "?>\n<?php", $variable); (If the string contains \r\n style newlines, use that instead of just \n.) Thanks mate!! works perfect.! Link to comment https://forums.phpfreaks.com/topic/184425-preg_replace-trouble/#findComment-973619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.