Здравствуйте. Есть скрипт index.php PHP: <?php header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); include("config.php"); include("modules/login.php"); #### Запуск сессии корзины покупателя session_start(); session_register("ses_tovar"); session_register("ses_kolvo"); include("modules/struct.php"); $template = stripslashes($template); #### Форма поиска по сайту if (strstr($template, "{SEARCH_FORM}")) { $searchForm = file_get_contents("files/temp/searchForm.html"); $template = str_replace("{SEARCH_FORM}", $searchForm, $template); } #### Корзина покупателя include("modules/cart.php"); #### Контент $tatel = mysql_query("select `element_id`, `type` from `".$prefix."blocks` where `page_id`='$page_id' ORDER BY `turn_id`"); while($rowel = mysql_fetch_array($tatel)) { if ($rowel['type']==0 AND !isset($newid) AND !isset($tshopid)) { #### Карта сайта include("modules/map.php"); } if ($rowel['type']==1 AND !isset($newid) AND !isset($tshopid)) { #### Тескстовый блок/статья $tat = mysql_query("select `datatext` from `".$prefix."article` where `id`='".$rowel['element_id']."' LIMIT 1"); $row = mysql_fetch_array($tat); $page_content.="<table class='blockmargin'><tr><td>".stripslashes($row['datatext'])."</td></tr></table>"; } if ($rowel['type']==2 AND !isset($newid) AND !isset($tshopid)) { #### Фотоальбом $tat = mysql_query("select * from `".$prefix."photoalbum` where `id`='".$rowel['element_id']."' LIMIT 1"); $row = mysql_fetch_array($tat); include("modules/photoalbum.php"); } if ($rowel['type']==3 AND !isset($newid) AND !isset($tshopid)) { #### Веб-форма $tat = mysql_query("select * from `".$prefix."webforms` where `id`='".$rowel['element_id']."' LIMIT 1"); $row = mysql_fetch_array($tat); include("modules/webforms.php"); } if ($rowel['type']==4 AND !isset($newid) AND !isset($tshopid)) { #### Гостевая книга $tat = mysql_query("select * from `".$prefix."blogs` where `id`='".$rowel['element_id']."' LIMIT 1"); $row = mysql_fetch_array($tat); include("modules/blogs.php"); $true_ajax = 1; } if ($rowel['type']==5 AND !isset($tshopid)) { #### Новостная лента $tat = mysql_query("select * from `".$prefix."newtapes` where `id`='".$rowel['element_id']."' LIMIT 1"); $row = mysql_fetch_array($tat); include("modules/news.php"); } if ($rowel['type']==6 AND !isset($newid)) { #### Интернет магазин $tat = mysql_query("select * from `".$prefix."shop_cats` where `id`='".$rowel['element_id']."' LIMIT 1"); $row = mysql_fetch_array($tat); include("modules/shop.php"); $true_ajax = 1; $this_pgshop = 1; } if ($rowel['type']==7 AND !isset($newid) AND !isset($tshopid)) { #### Опрос $tat = mysql_query("select `id` from `".$prefix."opros` where `id`='".$rowel['element_id']."' LIMIT 1"); $row = mysql_fetch_array($tat); $page_content.="{OPROS_".$row['id']."}"; $true_ajax = 1; } if ($rowel['type']==8 AND !isset($newid) AND !isset($tshopid)) { #### Форумы include("modules/forums.php"); } if ($rowel['type']==9 AND !isset($newid) AND !isset($tshopid)) { #### Тестирование $tat = mysql_query("select * from `".$prefix."tests` where `id`='".$rowel['element_id']."' LIMIT 1"); $row = mysql_fetch_array($tat); include("modules/tests.php"); } } #### Закрытая страница if ($accessPage==1 AND !strstr($accessGroup, "#".$group_global."#") OR $accessPage==1 AND $user_global==0) { $page_content = stripslashes($loginFormContent); } #### Новости if (strstr($template,"{LS_NEWS}")) { $tat2 = mysql_query("select * from `".$prefix."news` where `tape_id`='1' AND `newopen`='1' ORDER BY `date_id` DESC LIMIT 3"); while($row2 = mysql_fetch_array($tat2)) { $tatsb = mysql_query("select `anons` from `".$prefix."news_templates` where `id`='".$row['temp_id']."' ORDER BY `prime` LIMIT 1"); if (($rowsb = mysql_fetch_array($tatsb))==false) { $tatsb = mysql_query("select `anons` from `".$prefix."news_templates` where 1 ORDER BY `prime` DESC LIMIT 1"); $rowsb = mysql_fetch_array($tatsb); } if ($row2['photo']=="") { $newimg = "images/tex/spacer.gif"; $newimgbig = "images/tex/spacer.gif"; } else { $newimg = $row2['photo']."_small.jpg"; $newimgbig = $row2['photo'].".jpg"; } $new_shablon = str_replace("{NEWS_HEADER}", $row2['header'], $rowsb['anons']); $new_shablon = str_replace("{NEWS_HREF}", "NovostiNWID".$row2['id'].".html", $new_shablon); $new_shablon = str_replace("{NEWS_DATE}", $row2['cre_date'], $new_shablon); $new_shablon = str_replace("{NEWS_IMG}", $newimg, $new_shablon); $new_shablon = str_replace("{NEWS_BIGIMG}", $newimgbig, $new_shablon); $new_shablon = str_replace("{NEWS_ANONS}", nl2br($row2['anons']), $new_shablon); $new_shablon = str_replace("{NEWS_FULL}", $row2['datatext'], $new_shablon); $new_shablon = str_replace("{NEWS_TAPE}", $row['name'], $new_shablon); $new_shablon = str_replace("{NEW_CLASS}", "ans", $new_shablon); $all_newspage.=stripslashes($new_shablon); } $template = str_replace("{LS_NEWS}",$all_newspage,$template); } #### Подмены в шаблоне $template = str_replace("{PAGE_NAME}", stripslashes($page_fullname), $template); $template = str_replace("{PAGE_TITLE}", stripslashes($page_title), $template); $template = str_replace("{PAGE_METAKEY}", stripslashes($page_metakey), $template); $template = str_replace("{PAGE_METADESC}", stripslashes($page_metadesc), $template); $template = str_replace("{CONTENT}", $page_content."{AJAX}", $template); #### Переменная опроса if (strstr($template, "{OPROS_")) { include("modules/opros.php"); } #### Поиск по магазину if ($this_pgshop==1 AND $r_searchn!=1) { $r_search = file_get_contents("modules/scripts/shopsearch.html"); } $template = str_replace("{R_SEARCH}", $r_search, $template); #### Ошибка 404 if ($error404==1) { include("files/temp/404.html"); exit; } if ($rss==1) { $template = $rss_content; } #### Элементы и Баннеры сайта в шаблоне if (strstr($template, "{BANNER_")) { $tat = mysql_query("select `datatext`, `tag` from `".$prefix."banners` where 1 ORDER BY `id`"); while($row = mysql_fetch_array($tat)) { if (strstr($row['datatext'], "<?PHPCOD")) { $pathcod = "http://".$HTTP_HOST."/modules/phpcod.php?tag=".$row['tag']; $opencod = file_get_contents($pathcod); $template = str_replace("{BANNER_".$row['tag']."}", nl2br(stripslashes($opencod)), $template); } else { $template = str_replace("{BANNER_".$row['tag']."}", stripslashes($row['datatext']), $template); } } } #### Если нужен AJAX if ($true_ajax==1 AND $rss!=1) { $ajaxCod = file_get_contents("modules/scripts/goajax.html"); } $template = str_replace("{AJAX}",$ajaxCod,$template); echo $template; exit; ?> и есть шаблон к главной странице /files/temp/PGTemplate_1.html HTML: <html> <head> <title>{PAGE_TITLE}</title> <meta name="Description" content="{PAGE_METADESC}"> <meta name="Keywords" content="{PAGE_METAKEY}"> <link href="style.css" rel="stylesheet" type="text/css"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> </head> <body> <table width="100%" height="100%" cellpadding="0" cellspacing="0"> <tr><td> <table width="100%" cellspacing="0" cellpadding="0"> <tr><td width="260" height="241" background="images/bzs_01.jpg"><img src="images/tex/spacer.gif" width="260" height="1"></td> <td> <table width="100%" cellspacing="0" cellpadding="0"> <tr><td width="631" height="96" background="images/bzs_02.jpg"><a href="/"><img src="images/bzs_02.jpg" alt="Базис-Сервис" width="631" height="96" border="0"></a></td> <td background="images/bzs_03.jpg"> </td></tr> </table> <table width="100%" cellspacing="0" cellpadding="0"> <tr><td width="267" height="80" background="images/bzs_05.jpg"> </td> <td background="images/bzs_06.jpg"> </td> <td width="195" height="80" background="images/bzs_07.jpg"> </td></tr> </table> <table width="100%" cellspacing="0" cellpadding="0"> <tr><td width="5" height="65" background="images/bzs_08.jpg"> </td> {MENU_MAIN} <td width="22" height="65" background="images/bzs_16.jpg"> </td></tr> </table> </td></tr> </table> </td></tr> <tr><td height="100%"> <table width="100%" height="100%" cellpadding="0" cellspacing="0"> <tr><td width="249"> <table width="100%" height="100%" cellpadding="0" cellspacing="0"> <tr><td>{MENU_GR}</td></tr> <tr><td height="131" background="images/bzs_35.jpg"> </td></tr> <tr><td height="100%" background="images/bzs_37.jpg"> </td></tr> </table> </td> <td valign="top" background="images/bzs_18.jpg" class="xrep" style="padding:15px;"><h1>{PAGE_NAME}</h1>{CONTENT}</td></tr> </table> </td></tr> </table> </td></tr> <tr><td> <table width="100%" cellspacing="0" cellpadding="0"> <tr><td width="70" height="117" background="images/bzs_39.jpg"> </td> <td background="images/bzs_40.jpg" style="padding:10px;"> <table width=100%> <tr><td width=250>{BANNER_RAN}</td> <td align=right>{BANNER_RAN2}</td></tr> </table> </td></tr> </table> </td></tr> </table> <div style="position:absolute;top:15px;right:15px;"><a href="/"><img src="images/home.gif" alt="На главную" border="0" style="margin-right:25px;"></a><a href="mailto:{BANNER_MAIL}"><img src="images/mail.gif" alt="Написать письмо" border="0" style="margin-right:25px;"></a><a href="?printPage=1"><img src="images/print.gif" alt="Распечатать" border="0" style="margin-right:25px;"></a></div> <div style="position:absolute;top:110px;left:600px;">{BANNER_PHONE}</div> </body> </html> Подскажите как вставить в этот шаблон php код или как заставить php исполнятся в этом шаблоне? Буду очень благодарен!
Можно подробнее? Я ничего в этом примере не понял, вот чтобы мне проинклудить файл 1.php в шаблон что нужно в index.php прописать?
PHP: <?php include_once("index.php"); ?> а дальше настраиваем в .htaccess и он обрабатывать сможет php в html файле PHP: RewriteEngine on RewriteRule ^(.*)\.html $1\.php http://www.umade.ru/log/2004/07/use-php-in-html-pages/
PHP: ob_start ("callback"); function callback($buffer){ $buffer = str_replace('{{title}}',$title,$buffer); return $buffer; } ob_end_flush();
AddType application/x-httpd-php .php .htm .html AddHandler x-httpd-php .php .htm .html в конфиге апача или htaccess и можно инклюдить.
шаблонизатор берет шаблон и html файла функцией file_get_contents и отдает обработаный шаблон через echo Ну а теперь подумайте зачем Читайте внимательно пост #2