newbtophp Posted October 6, 2009 Share Posted October 6, 2009 (lol I dont want to sound greedy with all these requests but I have a little problem) How would i replace/remove all data within the first '$' and ');' characters (including replacing/removing the characters) Example <?php $ all data/code etc.); echo "test"; ?> Will turn into: <?php echo "test"; ?> I tried (but this just replaces the characters and not the code within aswell): $toreplace = array('$', ');'); $file = str_replace($toreplace, "", $file); Quote Link to comment https://forums.phpfreaks.com/topic/176750-solved-replace-specific-code/ Share on other sites More sharing options...
newbtophp Posted October 6, 2009 Author Share Posted October 6, 2009 anyone please <^>^<^> Quote Link to comment https://forums.phpfreaks.com/topic/176750-solved-replace-specific-code/#findComment-931971 Share on other sites More sharing options...
nrg_alpha Posted October 6, 2009 Share Posted October 6, 2009 Perhaps something along the lines of: $str = <<<EOF <?php $ all data/code etc.); echo "test"; ?> EOF; echo $str = preg_replace('#<\?php \K\$.+?\);\s?#s', '', $str); // Output (via right-click view source): <?php echo "test"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/176750-solved-replace-specific-code/#findComment-932025 Share on other sites More sharing options...
newbtophp Posted October 7, 2009 Author Share Posted October 7, 2009 Thanks nrg_alpha, Worked great although i didnt use your code, i used the expression and integrated it to the global variable. Solved Quote Link to comment https://forums.phpfreaks.com/topic/176750-solved-replace-specific-code/#findComment-932033 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.