call another php file in php code example

Example 1: php import function from another file

File1.php :
<?php
  function first($int, $string){ //function parameters, two variables.
    return $string;  //returns the second argument passed into the function
  }
?>
  
File2.php :
<?php
  include 'File1.php';
  echo first(1,"omg lol"); //returns omg lol;
?>

Example 2: run php script from another php

<?php 
include('log test.php');
$output = shell_exec('php filename.php');
echo "<pre>$output</pre>";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/Ia2/Watering/tests/log%20test.php"); //URL of the file
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec($ch);
curl_close($ch);
echo "<pre>$output</pre>";
?>

Tags:

Php Example