Include function ကိုအသုံးပြူ ၍ ပြင်ပတွင် သီးခြား ရှိနေသော file တစ်ခုအား လက်ရှိ
ရေးနေသော php file အတွင်းသို့ ဆွဲသွင်း နိုင်ပါသည်။
include("xxx.php")
အထက် ဖေါ်ပြပါ အတိုင်း include("xxx.php") ဟု ရေးလိုက် ခြင်းဖြင့် xxx.php
တွင်ရေးထား သမျှ code များအား လက်ရှိ ရေးနေသော php file အတွင်းသို့ ဆွဲသွင်း ကူးယူ
(copy) လိုက်စေ ပါသည်။
File တစ်ခုအား include လုပ်လိုက် သောအခါ:-
-
Include လုပ်ခံရသည့် file (ဤဥပမာတွင် xxx.php) သည် ၎င်း၏ အထက်တွင် ရေးထား
သမျှသော functions, classes နှင့် variables များကို အမွေ ဆက်ခံ အသုံးပြု
နိုင်သည်။
-
Include လုပ်ခံရသည့် file (ဤဥပမာတွင် xxx.php) တွင် ပါလာ သမျှသော functions,
classes နှင့် variables များကို လည်း include("xxx.php") စာကြောင်း
နောက်ပိုင်း ရေးသမျှ code များမှ အမွေ ဆက်ခံ အသုံးပြု နိုင်သည်။
Include နမူနာ
ဥပမာ သင်ရေး ထားသည့် web page အားလုံး ၏ ထိပ်တွင် ပုံစံတူ menu စာကြောင်း တခု
ထည့်သွင်း ချင်သည် ဆိုပါစို့။ အောက်ဖေါ် ပြပါ အတိုင်း menu.inc ဟုအမည် ပေးထားသော
file တခုကို ရေး၍ တနေရာတွင် save လုပ်ပါ။
menu.inc Code:
<html> <body>
<a href="index.php">Home</a> -
<a href="about.php">About
Us</a> -
<a href="links.php">Links</a> -
<a href="contact.php">Contact
Us</a> <br />
ပြီးလျင်၊ သင်ရေး ထားသော web page များ၏ ထိပ်တွင် အောက်ဖေါ်ပြ ပါအတိုင်း
include("menu.inc") ဟုရေးသွင်း လိုက်ပါ။
index.php Code:
<?php
include("menu.inc"); ?>
<p>
Web pages that uses a common
menu just need to include
'menu.inc' and all will have uniform menu.(save a lot of coding
works too)
</p>
</body>
</html>
သင်၏ web page တိုင်း၏ ထိပ်တွင်၊ Home - About Us - Links - Contact Us ဆိုသည့်
link ပါသော ပုံတူပန်းတူ စါကြောင်း တခု ပါလာ သည်ကို တွေ့ရ ပါလိမ့်မည်။
Display:
Home -
About Us
-
Links
-
Contact Us Web pages that uses a common menu just need
to include 'menu.inc' and all will have uniform menu.(save a lot of coding works
too)