Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php]Wczytywanie pliku .php przez file_get_contents .
Forum PHP.pl > Forum > PHP
Kaiba Ziom
  1. <?
  2.  define ("hehe", file_get_contents("test.php"));
  3.  
  4.  include("config.php");
  5.  class template
  6.  {
  7. function load_file($template, $file)
  8.  {
  9. if(!$fd = fopen("templates/$template/$file.html", 'r'))
  10. {
  11.  echo("<center><h1>Error</h1></center><br><center>Błąd w wczytywaniu skórki.</center>");
  12. }
  13. else
  14. {
  15. $rozmiar = filesize("templates/$template/$file.html");
  16. $result = fread($fd, $rozmiar);
  17. }
  18. return $result;
  19.  }
  20. function make_arg($file, $whatreplace, $result)
  21. {
  22.  $result = str_replace("<!--$whatreplace-->", $result, $file);
  23.  return $result;
  24. }
  25.  }
  26.  {
  27. $template = new template();
  28. if ($templates == 1) {
  29. $main_template = $template->load_file("1", "index");
  30. } elseif ($templates == 2) {
  31. $main_template = $template->load_file("2", "index");
  32. } elseif ($templates == 3) {
  33. $main_template = $template->load_file("error", "index");
  34. }
  35. {
  36. $test = file_get_contents('test.php');
  37. $main_template = $template -> make_arg($main_template, "login", "To jest logowanie");
  38. $main_template = $template -> make_arg($main_template, "login1", "To jest logowanie1");
  39. $main_template = $template -> make_arg($main_template, "test", hehe);
  40. }
  41.  }
  42.  echo $main_template;
  43. ?>

Mam taki plik , a w index.html mam:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-type" content="text/html; charset=iso-8859-2"/>
  4. <title>Nasza Tibia</title>
  5. <meta http-equiv="Content-Language" content="PL">
  6. <meta name="description" content="Rozbudowany serwis o wspaniałej grze MMorpg jaką jest Tibia.">
  7. <meta name="ROBOTS" content="index, follow">
  8. <meta name="Author" content="Mazur">
  9. <link rel="Stylesheet" type="text/css" href="./templates/1/style.css" />
  10. </head>
  11. <br />
  12. Hola Ziomy :)
  13. <p class="info">Test</p>
  14. <br>
  15. <!--test-->
  16. </body>
  17. </html>

w test.php:
  1. <?php
  2. echo 'nic';
  3. ?>

Chodzi o to że jeżeli napiszę <!--test--> to chcę mieć wartość test.php .
Lecz kiedy wchodzę w przeglądarkę to jak dam w test.php naprzykład:"test" to wyświetli się test , a jak dam
  1. <?php
  2. echo 'test';
  3. ?>

To nie ma tego sad.gif .
Co mogę zrobić?
kriqs


a tak na powaznie to popatrz w kod powinienes miec tresc pliku test.php czyli ta funkcja dziala smile.gif musisz to troszke inaczej zrobic np tak

  1. <?php
  2. function get_file( $file )
  3. {
  4. include($file);
  5. return $out;
  6. }
  7. ?>


chyba wiesz o co chodzi smile.gif .

dziekuje smile.gif
Kaiba Ziom
@up
Fajny królik biggrin.gif .
  1. <?
  2. $templates = '1';
  3. $file = 'test.php';
  4. function get_file( $file )
  5. {
  6.  ob_start();
  7.  include($file);
  8.  $out=ob_get_contents();
  9.  return $out;
  10. }
  11.  class template
  12.  {
  13. function load_file($template, $file)
  14.  {
  15. if(!$fd = fopen("templates/$template/$file.html", 'r'))
  16. {
  17.  echo("<center><h1>Error</h1></center><br><center>Błąd w wczytywaniu skórki.</center>");
  18. }
  19. else
  20. {
  21. $rozmiar = filesize("templates/$template/$file.html");
  22. $result = fread($fd, $rozmiar);
  23. }
  24. return $result;
  25.  }
  26. function make_arg($file, $whatreplace, $result)
  27. {
  28.  $result = str_replace("<!--$whatreplace-->", $result, $file);
  29.  return $result;
  30. }
  31.  }
  32.  {
  33. $template = new template();
  34. if ($templates == 1) {
  35. $main_template = $template->load_file("1", "index");
  36. } elseif ($templates == 2) {
  37. $main_template = $template->load_file("2", "index");
  38. } elseif ($templates == 3) {
  39. $main_template = $template->load_file("error", "index");
  40. }
  41. {
  42. $test = file_get_contents('test.php');
  43. $main_template = $template -> make_arg($main_template, "login", "To jest logowanie");
  44. $main_template = $template -> make_arg($main_template, "login1", "To jest logowanie1");
  45. $main_template = $template -> make_arg($main_template, "test", $file);
  46. }
  47.  }
  48.  echo $main_template;
  49. ?>


Niezbyt dobrze mi to wyszło :|
Przepraszam że taki jestem nie kapujący ale ucze się dopiero php i mam 13 lat tongue.gif .

Poprawka !
Dzięki ci exclamation.gif Głowiłem się nad tym bardzo długo biggrin.gif . Już naprawiłem THX THX I THX exclamation.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.