Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts

    Question PHP replace html variables

    Hey guys, i was wondering how would i go about replacing variables that i set in HTML to text through PHP. for example:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{$title}</title>
    </head>
    <body>
    so the code above would be my template file and then i would include that into a php file. and that php file would replace the {$title} part with what ever info is gathered from the database. Its pretty much what smarty does. I would use smarty but this is more of a learning thing right now. Thanks.

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    You would have to do this:

    PHP Code:
    <title><?php echo $php_title?></title>
    and then make the file a .php file and not .html
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #3
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    well see that's what i was doing before, but i wanted to know if there is some way i could make a class or function that would go through the html and look for variables in that form ({$title}). so like the php script would look for the info in the {} and then based on that would print the information that the variable holds. i hope this makes sense. I'm trying to make something similar to the smarty system. Thank you by the way for the response.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    I am unaware of any method that would actively force HTML files through a PHP engine... I guess you could have a file that goes through and writes a new temporary file each its accessed then forwards to that page, but that's the best through I have, and its pretty damn bad.


  •  

    Posting Permissions

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