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';"
When you want to return something, you need to use the return statement. A function can return any type of value in PHP.
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.
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>
$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.
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 Pagefile_get_contents()
PHP Documentation PageIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With