Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Niepoprawne wyświetlanie
Gibcio
post
Post #1





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 20.04.2005

Ostrzeżenie: (0%)
-----


Mam taką funkcję w pliku function.php do wczytywania zawartości pliku:
  1. <?
  2. function ReadTemplate($name) {
  3. $mainTemplate = file_get_contents($name);
  4. return $mainTemplate;
  5. }
  6.  
  7. function Menu() {
  8. echo "Menu";
  9. }
  10. ?>

index.php

  1. <?
  2. $title = "Tytul";
  3. include('function.php');
  4. $mainTemplate = ReadTemplate("template/blue/index.html");
  5. $mainTemplate = str_replace("<!--TITLE-->", $title, $mainTemplate);
  6. $mainTemplate = str_replace("<!--MENU-->", Menu(), $mainTemplate);
  7. echo $mainTemplate;
  8. ?>


index.html
  1. <title><!--TITLE--></title>
  2. </head>
  3. <table border="0" width="100%">
  4. <tr>
  5. <td width="100%" align="center"><!--TOP--></td>
  6. </tr>
  7. </table>
  8.  
  9. <table border="0" width="100%">
  10. <tr>
  11. <td width="20%" align="center"><!--MENU--></td>
  12. <td width="60%" align="center"></td>
  13. <td width="20%" align="center"></td>
  14. </tr>
  15. </table>
  16. </body>
  17. </html>

Problem jest taki że napis w funkcji Menu nie pojawia się w tej tabelce tylko zupełnie na górze strony - jak to rozwiącać, proszę o pomoc.

Z góry dziękuje!

Ten post edytował Gibcio 25.08.2007, 17:52:57
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Kicok
post
Post #2





Grupa: Zarejestrowani
Postów: 1 033
Pomógł: 125
Dołączył: 17.09.2005
Skąd: Żywiec

Ostrzeżenie: (0%)
-----


Po zwróceniu wyniku funkcja przestaje się już wykonywać (czyli zadziała tylko pierwsze przejście pętli). Nie wiem jak ty sobie wyobrażasz działanie takiej funkcji z returnem w pętli, ale może chodziło ci o coś takiego:

  1. <?php
  2.  
  3. function Menu()
  4. {
  5. $pozycje = '';
  6.  
  7.  
  8. $file = file( 'path_do_plik_z_pozycjami' );
  9. $total = count( $file );
  10.  
  11. for( $i=0; $total>$i; $i++ ) 
  12. {
  13. $b = explode( "||", $file[$i] );
  14.  
  15. $pozycje .= '<a href="' . $b[1] . '">' . $b[0] . '</a><br />';
  16. }
  17.  
  18.  
  19. return $pozycje;
  20. }
  21.  
  22. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 13.10.2025 - 10:57