Welcome to PHPMule.com
A blog site which I am posting to during my learning of the popular programming language PHP. Feel free to leave comments!
-
PHP - Loading Files Into Your PHP Script By Using require() and include()
If you wanted to reuse code from another file you could easily do this by using the require() or include() functions. These functions work exactly the same as server side includes files as in HTML.
These two functions work the same except when they fail to execute. If they fail the require() gives a fatal error and therefore stopping the execution of the remainder of the script and the include() function only gives a warning but doesn’t stop processing the script.
It’s recommended that you use the require() function rather than the include() function as your scripts shouldn’t be executing if for example your files are named wrong or placed in another directory.
Lets create a file called tester.php with the following file contents:
<?php
echo ‘I am a php script <br />’;
?>
Now in the index.php file we could have the following code:
<?php
echo ‘Another file will be included <br />’;
require ( ‘tester.php’ );
echo ‘Above is the contents of the tester.php file’;
?>
As you can see it’s quite simple to use other files in your php scripts and can save you a lot of time as you don’t need to reuse the code.
(Post created on Thursday, April 16th 09 at 13:50)
-
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
Archives
Recent Articles
- PHP - Rounding Off Numbers
- PHP - Single vs Double Quotation Marks
- PHP - Loading Files Into Your PHP Script By Using require() and include()
- PHP - Replacing Strings With Other Strings
- PHP - Finding Strings Within Strings
- PHP - Using strlen() To Test String Length
- PHP - Using The explode() Function
- PHP - Changing The String Case
- PHP - The nl2br() Function
- PHP - Trimming Strings
Links
Categories
- PHP (22)
- Uncategorized (1)


