Jump to content

Recommended Posts

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);

Link to comment
https://forums.phpfreaks.com/topic/269602-not-replacing/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/269602-not-replacing/#findComment-1385893
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/269602-not-replacing/#findComment-1385894
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.