March 24, 2012

Activating a php file from another php file

Question by Sedat KURT

I have abc.php and def.php files.For example I want to call def.php from abc.php .I found include() method but I don’t want def.php to activate in background.I want browser to redraw the page according to html-php codes of def.php

Any ideas ?

Answer by Starx

You can return the content of def.php

Here is an example:

Page: def.php

<?PHP
  //do many things, but do not echo or print anything
  $output ="<div> all the codes</div>"; // collect the markup like this
  return $output; // return the output but still do not echo or print
?>

Now Page: abc.php

//do its own processing
$myDefPageOutput = include("def.php"); 
//This will only get the values of the return statement

//Now user $myDefPageOutput wherever you want and redraw the page

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!