Hi!
I was wondering if there is any way to just include a small part of a file? If I write include("c:\wamp\www\somefile.php"); then the whole file is included. I would like to only include the half of the file or a variable. Is this possible?
Thanks in advance!

Hi!
I was wondering if there is any way to just include a small part of a file? If I write include("c:\wamp\www\somefile.php"); then the whole file is included. I would like to only include the half of the file or a variable. Is this possible?
Thanks in advance!

Why don't you just create a small include file with the relevant common bits in it, e.g. common.php. Then include that in other files (even other include files). Messing around with getting bits of files is a recipe for disaster if you update files from time to time.

Do something like this:

your big include file (C) contains include calls to 2 other include files (A and B). If other files/pages need to include one half of C, simply include A (or B) instead.

make two different files, the portion you want to include put just use that file as

include('myfile.php');

Hi!
I was wondering if there is any way to just include a small part of a file?
...
Is this possible?

Well actually yes it is possible. Just place an if element around what you don't want. Below is an example:

<? //index.php
$includes='t';
include('file.php');
?>
<? //file.php
echo 'This will be included.';
if ($includes!=='t') {
    echo '<br>This will not be included.';
    }
?>

As hard it may first seem ya just need to think past the barrier.

Thank you guys for your replies! It is just what I needed.
And now I'm going to try out all of the above mentioned methods.
:icon_smile:

This question has already been answered. Start a new discussion instead.