The Little Guy Posted July 16, 2012 Share Posted July 16, 2012 is there a way to replace all <? with <?php and leave all <?php alone? I am using javascript, but it is still regexp, so I thought I would post in the regexp section. I came up with this: code = code.replace(/\<\?[^php]/g, "<?php\n"); but it removes the first letter after php the beginning of the string: <?namespace becomes: <?php amespace as you can see the "n" is missing... Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted July 16, 2012 Share Posted July 16, 2012 $result = preg_replace('/<\?(?!php)/', '<?php', $subject); Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted July 16, 2012 Author Share Posted July 16, 2012 Thanks! That seems to work! Quote Link to comment 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.