Jump to content

Not Replacing?


3raser

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.