/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Problem when using php code in messages

Hi,

I am having a problem here… I want to insert php code in a message (for one of the messages in the message block of the screen).

The message body is stored in a database as text. When the page is displayed, the inserted php code is treated as text too and is not runned properly… I tried different things and nothing seem to work.

Is anyone have any idea of how to do that?

This is the php code line I want to insert in my message: [B].strtoupper(_CURRENT_MONTH_).”SPECIALS”[/B]

Thanks in advance!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 28.2014 — You would probably have to make use of eval(), but, "If eval() is the answer, you're probably asking the wrong question." More secure would be to just embed some sort of place-holder in there, then replace it via str_replace() or sprintf(), or printf(). E.g.:
[code=php]
$textFromDB = "blah blah blah _CURRENT_MONTH_ blah blah blah";
echo str_replace('_CURRENT_MONTH_', date('F'), $textFromDB);
[/code]
Copy linkTweet thisAlerts:
@php_coder_2014authorJun 28.2014 — Thank you NogDog!

It worked perfectly!

I should have seen that solution... Too easy! ?
×

Success!

Help @php_coder_2014 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...