Mailinglisten-Archive |
Hi.
>Das geht:
> if ($foo)
> { include ("foofoo.php3");
> }
>
>Das geht nicht:
> if ($foo)
> include ("foofoo.php3");
>
>Beim zweiten fall kommt immer dann ein parse-error, wenn innerhalb der
>foofoo.php3 mehr als eine zeile ist...
Ihr verweist doch immer so gerne auf das Manual.
function.include.html :
Because include is a special language construct, you must enclose it
within a statement block if it is inside a conditional block.
/* This is WRONG and will not work as desired. */
if ($condition)
include($file);
else
include($other);
/* This is CORRECT. */
if ($condition) {
include($file);
} else {
include($other);
}
When the file is evaluated, the parser begins in "HTML-mode" which will output the contents of the file until the first PHP start tag (<?) is encountered.
Dumme Lösung:
function myinclude ( $datei )
{ include ( $datei ); }
if ( $eslebt ) myinclude ( "datei.php3" )
Eigene Frage dazu:
Ich habe ein Script, das ein Datei includen soll, wenn eine Abfrage true ergibt:
if ( ereg ( "#INCLUDE1#" , $str ) )
{
$str = str_replace( "#INCLUDE1#", "", $str );
include ( $dir_includes.$include1 );
}
Die Variablen stimmen alle, das Script läuft auch soweit prima.
Nur, wenn $str (eine Zeile aus einer Textdatei) wirklich #INCLUDE1#
enthält (und meines Wissens nach der Code weiterhin ausgeführt wird),
kommt kein Inhalt zum Browser.
Sonst ist alles schön und gut.
Kann mir jemand weiterhelfen?
Tschüss,
Lasar
.sig _____________________________________________________________________
Lasar Liepins . http://www.liepins.de . lasar_(at)_liepins.de . dmoz.org editor
php::bar PHP Wiki - Listenarchive