Escape Characters

In both types of string:

  '  needs to be  \'
  \  needs to be  \\

In ” ” strings:

  "  needs to be  \"
  \t    tab
  \n    new line
  \r    return

Note, using say ‘\n’ will not create a newline character, it will create the characters \n !!!!! \n only works in a “” string!!

Joining strings

Use the period character ‘.’

You can also use .=

    $body = "Some text";
    $body .= "Some more text";

Is String Empty

	$my_string = trim($my_string);
	if (!empty($my_string))
		//Do something


  $length = strlen($MyString);

‘ vs “

‘ single quotes assigns a string using its exact contents. So if you want to include variables you have to do this:

   echo 'His name is ' . $name . ' and his age is' . $age';

” double quotes assigns a string but if the string contains a variable name the php parser will attempt to evaluate it, so you can use it like this:

   echo "His name is $name and his age is $age";

Echo A Block Of Text

echo "Some


blah blah";

Heredoc string

See here

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.