www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Problem when using php code in messages

  1. #1
    Join Date
    Jun 2014
    Posts
    2

    resolved [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: .strtoupper(_CURRENT_MONTH_)."SPECIALS"

    Thanks in advance!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,246
    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.:
    PHP Code:
    $textFromDB "blah blah blah _CURRENT_MONTH_ blah blah blah";
    echo 
    str_replace('_CURRENT_MONTH_'date('F'), $textFromDB); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2014
    Posts
    2
    Thank you NogDog!

    It worked perfectly!

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles