PHP Snippets: Quotes

PHPThis post is part of the PHP Snippets series where I will be covering the basics of developing in PHP.

Both single and double quotes are supported in PHP, but there is a significant difference in how they are handled.

Single quotes are output “as is” and are the quickest form of quoting. When using single quotes, you would need to concatenate variables with a string to output them:

$fruit = 'apples';

echo 'They drank some juice from ' . $fruit;

Double quotes evaluate variables and many escaped characters. This means you do not need to concatenate variables with the string, but can include them inside the double quoted string:

$fruit = 'apples';

echo "They drank some juice from $fruit";

You can also use curly braces ({} to isolate the variable within the string. When PHP evaluates a string and sees a $ it will take as much of the string as part of the variable name (ending at a space or punctuation), but you can use the curly braces to explicitly set the end of the variable name:

$fruit = 'apple';

echo "They drank some juice from ${fruit}s.";

Can ISC Software Solutions help?

ISC Software Solutions are UK and Ireland based experts on Microsoft Dynamics GP. If you’d like to speak to someone about support, consultancy, upgrades, implementation, development, GP Elementz add-ons or portals, or anything else Dynamics GP related, you can use the form below.





Your Name (required):
Your Email (required):
Subject:
Enquiry message:

What should we write about next?





Your Name (required) –
Your Email (required) –

Leave a Reply

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