String Variable

Onto the most flexible variable in PHP, the string variable. You might notice how I keep referring to strings as variables. However, strings are much more like objects with methods and properties. Only the string object’s properties is what you might think of as the string. However, I won’t discuss objects much in the early tutorials because they are a bit more complicated. You can manipulate a string in almost every way imaginable in PHP. Previously you already learned how to create a string variable by putting the actual string in quotes following the variable name.

Example

Result

Champions

Nothing special here. We are just echoing a string variable just like before. What if we want to join strings with other strings or strings with variables?

Joining Strings

The concatenation operator in PHP is a little bit odd in comparison. The . joins everything together. Weird choice isn’t it? I thought so.

Example

Result

We are the Champions of the world.

Yes, I was rocking out to that song while writing this. You should too! We have the string “We are the “ that we join to $myVar and again to ” of the world”. That is truly all we have for the simple side of strings. Check out the PHP Strings tutorial to get into more advanced string functions.

If you enjoyed this resource, support me by sharing this page with others.
Share on Facebook
Facebook
Share on Google+
Google+
Share on StumbleUpon
StumbleUpon
Digg this
Digg
Tweet about this on Twitter
Twitter
Share on Reddit
Reddit

Leave a Comment

  1. the link for download "we are the champions" is no longer working due to copyright restrictions in you tube, but there are other thousands

Leave a Reply

Your email address will not be published. Required fields are marked *