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
    Posts
    282

    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
    Location
    Kansas City area
    Posts
    19,435
    PHP Code:
    $text 'Why hello there {name}, how are you today?';
    $name 'Brad';

    $text str_replace('{name}'$name$text);
    echo 
    $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
    Location
    Ankh-Morpork
    Posts
    14,534
    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:
    Code:
    <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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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
  •