Code: Select all
<?php
// Set what ever you want functionHere() to be. MUST include ().
function testHere($x, $y) {
// Your content here.
echo "Your username is $x and your Nick Name is $y.";
}
?>
<?php
// Include the file and stop if it can't be included. Ours will be 'test.php'
@require_once('test.php') or die('Error: failed to include test file.');
// Use and set functions. Where the first area of ($x, $y) is your username and $y is what you like to be called.
testHere('my username','my nickname');
?>
Fixed.
Important files should use require() or require_once(), that way the script fails if they cannot be included for some reason. Prepending the function call with a @ supresses the error output. A failed include may give away the path to your PHP script/web folder, which will assist someone trying to compromise your site/server.
$variables can be inserted into any double-quoted string. If you need the character $ to appear inside a double-quoted string, use \$. Otherwise, use single-quoted strings (e.g. 'example') as they're parsed faster by the PHP interpreter.
------------------
Another small thing that most people don't realize:
PHP (like Perl, which most of PHP's half-implemented features are stolen from) supports "here document" syntax. Do NOT do retarded stuff like this:
Code: Select all
<?php
$html = "<html>";
$html .= "<head>";
..........
$html .= "</html>";
echo $html;
?>
Instead, opt for this:
Code: Select all
<?php
$html =<<<EOF
<html>
<head>
.............
</html>
EOF;
echo $html;
?>
Note that you can also insert $variables into the block of code between the EOFs (also, EOF can be whatever you want, but keep in mind that the ending EOF cannot have ANY spaces before it. It must be the first thing on the line and be by itself.)
You can also use here-documents to output things rather than assign them to a variable:
Code: Select all
<?php
$time = time();
echo <<<EOF
The current Unix timestamp is: $time
EOF;
?>
Amazing.
And makes code so much more readable, especially when dealing with HTML.