Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get returned text from a php page

Tags:

php

very simple php question,

for example, demo.php just returns a text like this "hello".

how can i get this text from an another php page ?

UPDATE:

actually i meant page is outputting it like this "print 'hello';"

like image 387
Utku Dalmaz Avatar asked Feb 13 '10 21:02

Utku Dalmaz


People also ask

How do you return something in PHP?

When you want to return something, you need to use the return statement. A function can return any type of value in PHP.

Does PHP have return?

Definition and UsageThe return keyword ends a function and, optionally, uses the result of an expression as the return value of the function. If return is used outside of a function, it stops PHP code in the file from running.

What is $_ GET [' page ']?

PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. Assume we have an HTML page that contains a hyperlink with parameters: <html> <body>

What is return $this in PHP?

$this means the current object, the one the method is currently being run on. By returning $this a reference to the object the method is working gets sent back to the calling function.


1 Answers

Does it return "hello", does it output hello or does it simply contains hello? All three scenarios are different problems.


If it return "hello"; as such:

<?php
return "hello";

then you can easily grab its value by including the file and grabbing the return value:

<?php
$fileValue = include('secondFile.php');

If it outputs hello as such:

<?php
echo "hello"; // or print "hello";

you must use output buffering to capture the result:

<?php
ob_start();
include('secondFile.php');
$fileValue = ob_get_contents();
ob_end_clean();

If it contains hello as such:

hello

you can simply read the result:

<?php
$fileValue = file_get_contents('secondFile.txt');

See Also:

  • include() PHP Documentation Page
  • Output Buffering PHP Documentation Section
  • file_get_contents() PHP Documentation Page
like image 111
Andrew Moore Avatar answered Oct 08 '22 10:10

Andrew Moore