View Full Version : PHP replace html variables

06-19-2010, 12:47 AM
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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
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.

06-19-2010, 05: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

06-21-2010, 10: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.

06-21-2010, 10: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.