Skip to content

Instantly share code, notes, and snippets.

@sirkitree
Created August 24, 2011 04:42
Show Gist options
  • Save sirkitree/1167322 to your computer and use it in GitHub Desktop.
Save sirkitree/1167322 to your computer and use it in GitHub Desktop.
Strings & Variables
<?php
// The following sentence in quotes is a basic string that is printed to the screen.
print "Hi, I am proud!";
// You can assign a string to a variable for storage and then print the variable.
$sentence = "Hi, I am proud!";
print $sentence;
// You can combine strings in various ways using the period (.) for concatenation.
$sentence = "Hi, I am proud!" . " And because I am proud I have self-worth!";
print $sentence;
// This will result in the following output to the screen:
// Hi, I am proud! And because I am proud I have self-worth!
// If you have two strings assigned to variables, you can concatenate the variables and get the same result.
$first_sentence = "Pride is a basic human instinct.";
$second_sentence = " Without pride, I wouldn't have any self-worth.";
print $first_sentence . $second_sentence;
// Notice that within the quotes of the $second_sentence I started with a space.
// If I didn't, when this is printed it would run together like this:
// Pride is a basic human instinct.Without pride, I wouldn't have any self-worth.
// You could get the same result by concatenating a space in-between the variables like so:
$first_sentence = "Pride is a basic human instinct.";
$second_sentence = "Without pride, I wouldn't have any self-worth.";
$third_sentence = "Without self-worth, I wouldn't have enough value to want to further myself by learning PHP."
print $first_sentence . " " . $second_sentence . " " . $third_sentence;
// Disclaimer: pride is honorable until it is felt for reasons that are undeserving.
// Unwarranted or undeserved pride is what leads to dishonor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment