Tutorial for Single Quoted String

What is Single Quoted string?

In PHP, we can make a string by surrounding the content in a single quotation mark. In PHP, it is the simplest way to specify a string.

Escape a literal single quote with a backslash (), and use double backslash to specify a literal backslash (). (\). All other backslash characters, such as r and n, will be output as they are instead of having any special meaning.

How to Create Strings Using Single quotes with Example.

Let’s have a look at the four alternative approaches to writing PHP string functions and manipulating strings in PHP.

Using Single Quotes to Build PHP Strings: The simplest approach to create a string is to use single quotes.

Let’s have a look at a PHP example that generates a simple string.

Example 1:-

Output:

Hello text within single quote

Example 2:-

Output:

Hello text multiple line text within single quoted string 
Using double "quote" directly inside single quoted string 
Using escape sequences \n in single quoted string

Example 3:-

Output:

trying variable $num1 
trying backslash n and backslash t inside single quoted string \n \t 
Using single quote 'my quote' and \backslash

Tagged : / / / / / /