3raser Posted October 17, 2012 Share Posted October 17, 2012 I've checked all variables, and they are set correctly. However, no matter what - I can't seem to get the following line of code to actually replace the [donator][/donator] pattern with the contents within it. input [donator] this is a test[/donator] //show content within [donator] tags only to donators $content = preg_replace('#\[donator\](.+?)\[\/donator\]#im', (($user->isDonator($user->getUsername($_COOKIE['user'], 2)) || $rank > 1) ? '<div class="donator_only">$1</div>' : null), $content); Quote Link to comment https://forums.phpfreaks.com/topic/269602-not-replacing/ Share on other sites More sharing options...
Christian F. Posted October 17, 2012 Share Posted October 17, 2012 Move the logic out of the presentation (preg_replace ()), and store the content to insert in a variable instead. Doing everything on one line is asking for troubles, as it's terrible for readability. BTW: You don't need to escape that slash in the RegExp, as it has no special meaning since you've used hash-signs for delimiters. Quote Link to comment https://forums.phpfreaks.com/topic/269602-not-replacing/#findComment-1385893 Share on other sites More sharing options...
3raser Posted October 18, 2012 Author Share Posted October 18, 2012 Move the logic out of the presentation (preg_replace ()), and store the content to insert in a variable instead. Doing everything on one line is asking for troubles, as it's terrible for readability. BTW: You don't need to escape that slash in the RegExp, as it has no special meaning since you've used hash-signs for delimiters. Ah, thanks. Fixed that. I've also gotten everything to work: however, it still doesn't seem to support multiple lines. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/269602-not-replacing/#findComment-1385894 Share on other sites More sharing options...
Christian F. Posted October 18, 2012 Share Posted October 18, 2012 Yep, the "s" modifier for PCRE Regular Expressions. The PHP Manual has more information on it, and I recommend reading through it. (http://php.net/pcre) Quote Link to comment https://forums.phpfreaks.com/topic/269602-not-replacing/#findComment-1385896 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.