PHP Bildirimi içerir

4 Cevap php

Çalıştığım yer alıyor merak ediyorum. i büyük bir dosya içine 2 dosyalarını veya daha fazla hale düşündüm

for example file 1 includes file 2. file 1 is in the root directory while file 2 is in root/include/file2. so if file 2 needed to include something from the root/include directory then instead of putting include("file3.php"); i would need to put include("root/include/file3.php"); so then all 3 files are considered by the server to be one big file.

i aslında nasıl yere yakın değilim?

4 Cevap

PHP manuel:

Files are included based on the file path given or, if none is given, the include_path specified. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error.

If a path is defined (full or relative), the include_path will be ignored altogether. For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file.

Eğer göreli yolları belirtirken endişelenecek istemiyorsanız Yani include path / root / içerecek şekilde ayarlanmış. Daha sonra sadece kullanabilirsiniz

include("filename");

herhangi bir dosya. Bu dosyayı açamıyor eğer ölümcül bir hata atıyor gibi ben de işlevi bakarak öneririm () gerektirir.

Dan the documentation:

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs.

Yani arasındaki etkileşimler dosyalarını içerir tamamen birbirleriyle onları dahil hangi kapsam bağlıdır. Yollar tam veya göreli veya include_path saygı içinde ihmal edilebilir verilebilir.

Bir dosyanın içeriğini alır ve include ifadesi takılı yere koyar içerir.

It is important to note that the included file is previously parsed by the PHP interpreter, so you can do things such as

(! @ () dahil) {echo 'kullanıcı düzenlenen dosya bir sözdizimi hatası, varsayılan restore edilmiş.')}

Ne include yapar bu bir dosyayı yapıştırır olduğunu.

Eğer varsa söyle a.php:

Hello,

Ve b.php:

world!

Sonra c.php:

<?php include "a.php"; include "b.php"; ?>

Olacak:

Hello, world!

PHP tarafından zaman. PHP bazı sihirli şeyler yapar, ama bu temel etkisidir.

Eğer ("merhaba / world.php" gibi) başka bir dizine bir dosyayı kullanmak gerekiyorsa, o tam göreceli yolunu değil, sadece dosya adı kullanmak zorunda.