在另一个PHP中执行PHP

I have following 2 php pages which is actually containing html tags (in 2nd page only) with out php tag start and end.

page1.php

<div>Page 1</div>
<?php exec('/usr/bin/php page2.php');
?>

page2.php in same directory

<div> this is page 2</div>

Actual result : 2nd page is not printed when page1.php is executed

Expected result: both page 1 and page 2 php result should come in page1.php when hit from broswer.. in this case , following is the expected result..

Page 1
this is page 2

Note : This is just an example. my page is containing 1000s of lines in page2.php

You're looking for require or include (or in particular, probably require_once)

i.e.

<div>Page 1</div>
<?php 
    require("page2.php");
?>

Unless you're trying to do something far stranger than i've anticipated.

Per the docs, exec only returns (i.e. you'd have to echo it) the last line of the output. passthru or system would work better, but you really should be using include or require instead.

Use the following on page1.php:

<div>Page 1</div>
<?php 
include ("page2.php");
?>

Hope that works for you... :)

You can use it multiple time in a php file <div>Page</div> <?php include once "page2.php"; or require once "page2.php"; ?>

<input type="hidden" name="id" value="<?=$data['id_rm']?>">
<label for="pasien">Nama Pasien</label>
<select name="pasien" id="pasien" class="form-control" required>
    <option value="<?=$data['id_pasien']?>" selected="selected"><?=$data['nama_pasien']?></option>
    <option value="">- Pilih Pasien -</option>
    <?php 
        $sql_pasien = mysqli_query($con, "SELECT * FROM tb_pasien") or die(mysqli_error($con));
        while($data_pasien = mysqli_fetch_array($sql_pasien)) {
            echo '<option value="'.$data_pasien['id_pasien'].'">'.$data_pasien['nama_pasien'].'</option>';
        }
    ?>
</select>