The primary difference between single and double quotes in PHP is interpolation. With double quotes, you are able to interpolate between a string and a variable in php, for example you could use echo "<p>My variable contains: $myvar</p>" to show what the $myvar variable contains. Single quotes do not allow for this to be done.
There are many debugging techniques and it is difficult to convey everything about debugging in such a short page, but below are some tips.
display_errors is on for more detailed errors$_SERVERThe $_SERVER variable holds information relating to the server running php and the request. For example, your current IP address is 216.73.216.131, which was obtained by using <?php echo $_SERVER['REMOTE_ADDR']; ?>. Yes that is your actual IP address.
Landon Hansen LANDON HANSEN landon hansenName is 13 characters long1.2857 3,005Name: Landon Hansen Age: 17 DOB: September 4, 2007
function showOutput($out) {
echo "<div><span>";
echo $out;
echo "</span></div>";
}
// define variables "that hold your full name and age"
$name = "Landon Hansen";
$age = 17;
// "Create a constant that holds another bit of information about you that won't change"
define("DATE_OF_BIRTH", "September 4, 2007");
// find the length of the provided name
$name_length = strlen($name);
// print the name 3 different ways, and show name length
showOutput($name . " " . strtoupper($name) . " " . strtolower($name));
showOutput("Name is $name_length characters long");
// show example output of number_format
showOutput(number_format(9 / 7, 4) . " " . number_format(3005));
// concatenation example
showOutput('Name: ' . $name . ' Age: ' . $age . ' DOB: ' . DATE_OF_BIRTH);
// get the php code in this file at the given index
function get_php_code($file, $index = -1) {
$rawFile = file_get_contents($file); // get this file's contents
$lastPHP = explode("<?" . "php", $rawFile); // split by php starting sequence. Not perfect but it's good enough for this.
return str_replace(
"", "", // remove initial tabs
str_replace("\n", "<br>", // replace newlines with <br>
htmlspecialchars( // escape html
explode("?" . ">", $lastPHP[$index])[0] // get the php block by index and get everything before the ending sequence
)
));
}
// show the actual php code
showOutput(get_php_code(__FILE__, 2));
showOutput(get_php_code(__FILE__, 4));