sKunKbad Posted April 21, 2012 Share Posted April 21, 2012 I'm trying to replace the spaces, or what will be a current list of IP addresses that are between the 2 comments in this string <?php $deny_list = ' 123.123.123.123 222.222.222.222 '; $string = ' ## IP BANNING <Limit GET POST> order deny,allow # BEGIN DENY LIST -- # END DENY LIST -- </Limit> '; $pattern = '/(\# BEGIN DENY LIST --)(.*?)(\# END DENY LIST --)/'; $string = preg_replace( $pattern, $deny_list, $string ); echo '<pre>'; echo htmlentities( $string ); echo '</pre>'; Can't figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/261387-preg_replace-between/ Share on other sites More sharing options...
.josh Posted April 22, 2012 Share Posted April 22, 2012 need the "s" modifier so that your "." will match newline chars. Quote Link to comment https://forums.phpfreaks.com/topic/261387-preg_replace-between/#findComment-1339442 Share on other sites More sharing options...
sKunKbad Posted April 22, 2012 Author Share Posted April 22, 2012 This ended up working for me: '/(?<=# BEGIN DENY LIST --)(.|\n)*(?=# END DENY LIST --)/' Quote Link to comment https://forums.phpfreaks.com/topic/261387-preg_replace-between/#findComment-1339557 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.