...

View Full Version : PHP replace html variables



slappyjaw
06-18-2010, 11:47 PM
Hey guys, i was wondering how would i go about replacing variables that i set in HTML to text through PHP. for example:

<!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.

rfresh
06-19-2010, 04:51 AM
You would have to do this:



<title><?php echo $php_title?></title>


and then make the file a .php file and not .html

slappyjaw
06-21-2010, 09:56 PM
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.

Keleth
06-21-2010, 09:59 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum