Using PHP in a text field... like how Wordpress does
Results 1 to 3 of 3

Thread: Using PHP in a text field... like how Wordpress does

  1. #1
    Senior Member
    Join Date
    Oct 2003

    Using PHP in a text field... like how Wordpress does

    I have no idea how this is done.

    But, Wordpress and some other scripts use tags like {something}

    inside of a text box... and the {sometime} becomes a PHP variable...

    hope someone knows what I mean here, not really even sure how to ask!

    but hoping to figure out how to do this...
    I <3 PHP Builder!

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Kansas City area
    PHP Code:
    $text 'Why hello there {name}, how are you today?';
    $name 'Brad';

    $text str_replace('{name}'$name$text);
    $text// Why hello there Brad, how are you today? 
    Or were you looking for something more generic? If so, you could do a preg_match_all() to find all occurrences of {something} (where 'something' looks like whatever you want, e.g. a valid PHP variable name). You could then walk through the array of matches and use isset() to determine if a PHP variable exists and, if so, str_replace() the placeholder with its value.

  3. #3
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    There are various templating engines out there that use a similar syntax. Probably the most popular is Smarty, which to simply output a PHP variable uses something like:
    <p>Hello, {$username}.</p>
    This is not built-in functionality for PHP -- you would need to download and include Smarty to have it parse such template files.
    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." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~

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