PHP Web Development Delhi

PHP is a reflective programming language originally designed for producing dynamic web pages.PHP is used mainly in server-side scripting, but can be used from a command line interface or in standalone graphical applications. Textual User Interfaces can also be created using ncurses. PHP generally runs on a web server, taking PHP code as its input and creating Web pages as output, however it can also be used for command-line scripting and client-side GUI applications. PHP can be deployed on most web servers and on almost every OS platform.

What is String?

In programming, a string is a sequence of letters, symbols, characters and arithmetic values or combination of all tied together in single or double quotes. For example, “I Love PHP”, “10”, ‘100.01’, “”, etc are all examples of strings.

Declaring String Variable in PHP

An example:

$my_name = “web dhoom”;

In PHP, a variable must start with $ sign followed by variable name. The string value must be wrapped in double or single quotes.

Concatenate / Join Strings in PHP

Sometimes while working with strings in our code, we need to join two strings. In PHP, you can use ‘.’ to concatenate two or more strings together to form a single string.

An Example:

$my_first_name = “web dhoom “;

$my_last_name = “Doe”;

//concatenate my first and last name

$my_full_name = $my_first_name. ” ” . $my_last_name;

echo $my_full_name;

The above example with output “Web dhoom Doe”.

Single and Double Quotes PHP Strings

Double Quotes:

Strings in PHP can be wrapped in double or singles quotes. Using double quotes is the primary method. Double quotes allow us to escape specials characters in our string. For example, when you use the $ sign within double quotes it is treated as php variable and will not show up in the output

An Example:

$str = “hello”;

echo “$str everyone!”;

Notice in the above code, we wrapped the $str variable in double quoted string. The above example will output “hello everyone” NOT “$str everyone”

Single Quotes:

Single quotes can be used to do things like…

An example:

$quote_of_the_day = ‘”To be or not to be. That is the question”‘;

echo $quote_of_the_day;

Notice, we used double quotes around the text. The code will output “To be or not to be. That is the question”.

Single Quotes vs. Double Quotes in PHP Strings

It is good practice when working PHP code to wrap stings in double quotes. Single quotes should be used when writing HTML code within PHP code since attribute values of HTML tags should be wrapped in double quotes as good coding practice.

Sandeep Sankar

Author at Webdhoom
Sandeep Shankar is a content writer with Webdhoom, a digital marketing firm, which assists both startups and established businesses to improve online traffic, reach out to target audience, increase sales and build loyal customers through best SEO and SMO services. His articles and blogs are widely read and shared on different online platforms.
Sandeep Sankar
Sandeep Sankar
Sandeep Shankar is a content writer with Webdhoom, a digital marketing firm, which assists both startups and established businesses to improve online traffic, reach out to target audience, increase sales and build loyal customers through best SEO and SMO services. His articles and blogs are widely read and shared on different online platforms.