What is string manipulation php?

In this tutorial you will learn how to store and manipulate strings in PHP.

What is String in PHP

A string is a sequence of letters, numbers, special characters and arithmetic values or combination of all. The simplest way to create a string is to enclose the string literal [i.e. string characters] in single quotation marks ['], like this:

$my_string = 'Hello World';

You can also use double quotation marks ["]. However, single and double quotation marks work in different ways. Strings enclosed in single-quotes are treated almost literally, whereas the strings delimited by the double quotes replaces variables with the string representations of their values as well as specially interpreting certain escape sequences.

The escape-sequence replacements are:

  • \n is replaced by the newline character
  • \r is replaced by the carriage-return character
  • \t is replaced by the tab character
  • \$ is replaced by the dollar sign itself [$]
  • \" is replaced by a single double-quote ["]
  • \\ is replaced by a single backslash [\]

Here's an example to clarify the differences between single and double quoted strings:

Chủ Đề